# 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)
}
# Functions
WaitUntil wait until for fn returning true or done is close or message arrived from done channel.
# Constants
EnvMQClientConfigPath environment variables for config path.
# Variables
ErrAlreadyConnected client had connected to server.
ErrNotConnected client not connect to the server.
ErrTimeout operation timeout.
ErrTopicMissing topic parameter missing.
# Type aliases
Fn call back function.
OnDisconnect disconnect callback if user call Disconnect, then error will be nil.
OnMessage message income callback.