基于 PAHO 客户端处理多个 MQTT 服务器/集群
Go to file
2022-12-16 01:01:07 +03:30
.github/workflows feat: Add Coverage Report 2021-06-06 17:23:54 +04:30
example/cli feat: move example to its package 2021-11-17 20:31:19 +03:30
pkg feat: update package name to snapp-incubator 2021-09-08 14:19:08 +04:30
test fix: correct lint issues 2021-09-08 14:31:10 +04:30
.gitignore Add vscode and intellij config files to gitignore 2021-05-09 16:40:27 +04:30
.golangci.yml chore: ignore lint issues for now 2021-11-17 20:39:02 +03:30
.goreleaser.yml feat: update goreleaser 2021-11-17 20:32:10 +03:30
docker-compose.yml fix: Correct Docker-Compose 2021-05-07 08:01:52 +04:30
go.mod feat: remove example dependencies from pakhshi 2021-11-17 20:31:46 +03:30
go.sum feat: remove example dependencies from pakhshi 2021-11-17 20:31:46 +03:30
LICENSE Initial commit 2021-05-06 08:55:35 +04:30
README.md Update README.md 2022-12-16 01:01:07 +03:30

pakhshi

GitHub Workflow Status GitHub Workflow Status Go Reference Codecov

Introduction

Consider you have an array of brokers but you want to publish and subscribe on all of them at the same time. Why you may need this setup? consider clients are randomly distributed between available clusters and you don't want to check which client is connected to which broker so you will publish on all cluster and your client is connected to one them.

How?

This library use paho in the background so you can easily change your applications to use this instead of paho. It trying to implement all paho interfaces.

Examples

The following example shows how to subscribe on the same topic on two brokers.

opts := mqtt.NewClientOptions()
opts.AddBroker("tcp://127.0.0.1:1883")
opts.AddBroker("tcp://127.0.0.1:1884")

c := client.NewClient(opts)

if token := c.Connect(); token.Wait() && token.Error() != nil {
  assert.NoError(t, token.Error())
}

if token := c.Subscribe("hello", 0, func(c mqtt.Client, m mqtt.Message) {
  ch <- string(m.Payload())
}); token.Wait() && token.Error() != nil {
  assert.NoError(t, token.Error())
}

Credits

Based on idea of Ahmad Anvari.