Categorygithub.com/enix223/go-mqclient
modulepackage
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:

  1. Take care reconnect for you, and will also help you subscirbe the topics when reconnected
  2. yaml/json/toml/environment based config to simplified library configuration. Thanks to configor
  3. 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

  1. Run with rabbitmq as broker
make example-rabbitmq
  1. 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)
}

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# 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.

# Structs

Message MQ message.
Subscription message subscription.

# Interfaces

Client an interface for message queue client.
Factory MQClient factory.
Logger logger.

# Type aliases

Fn call back function.
OnDisconnect disconnect callback if user call Disconnect, then error will be nil.
OnMessage message income callback.