repositorypackage
0.7.0
Repository: https://github.com/enix223/go-mqclient.git
Documentation: pkg.go.dev
# README
go-mqclient
A generic mq client library with uniform interfaces, which support rabbitmq, mqtt brokers
Features:
- Take care reconnect for you, and will also help you subscirbe the topics when reconnected
yaml
/json
/toml
/environment
based config to simplified library configuration. Thanks to configor- Uniform interface which hides the detail of different brokers
Install
go get -u github.com/enix223/go-mqclient
Play with the example
For more detail please refer to example/client.go
- Run with rabbitmq as broker
make example-rabbitmq
- Run with paho eclipse mqtt sandbox server
make example-mqtt
Usage
// 1. Factory to build a MQ client base on given type
// rabbitmq as backing client
client = rabbitmq.CreateMQClient()
// or MQTT client
client = mqtt.CreateMQClient()
// 2. Connect to the MQ server
err := client.Connect();
// 3. subscribe
err := client.Subscribe(nil, onMessage, topic1, topic2);
// 4. publish topic
err := client.PublishTopic(topic, []byte("123"), nil)
// 5. disconnect
client.Disconnect()
// 6. Message callback
func onMessage(payload *mqclient.Message) {
log.Println(payload)
}