RabbitMQ Library to using Event Driven Application based on Publish/Subscribe built with Go
- First before use this library you should create new amqp client
// set configuration
config := amqp.Config{
ServiceName: "EXAMPLE",
Host: "localhost",
Port: 5672,
User: "guest",
Password: "guest",
}
// open connection to amqp server
client, err := amqp.NewClient(config)
if err != nil {
fmt.Println(err.Error())
return
}
- Setup Publisher
import "github.com/Gate2Up/rabbitmq-go/publisher"
// define topic name
var topicName = "EXAMPLE"
// create instance of publisher
var Publisher = publisher.NewPublisher(topicName, nil)
// register publisher to amqp
client.AddPublisher(Publisher)
- Setup Subscriber
import (
"fmt"
"github.com/Gate2Up/rabbitmq-go/subscriber"
)
// create handler function
func handler(data []byte) error {
fmt.Println(data)
return nil
}
// create instance of the subscriber
var Subscriber = subscriber.NewSubscriber("SUBSCRIBER_NAME", nil, handler)
// register subscriber to amqp
client.AddSubscriber(Subscriber)
- Go client for AMQP 0.9.1