Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/snapp-incubator/pakhshi
handle multiple mqtt server/cluster based on paho client
https://github.com/snapp-incubator/pakhshi
go golang mqtt
Last synced: about 1 month ago
JSON representation
handle multiple mqtt server/cluster based on paho client
- Host: GitHub
- URL: https://github.com/snapp-incubator/pakhshi
- Owner: snapp-incubator
- License: gpl-3.0
- Created: 2021-05-06T04:25:34.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-12-15T21:31:07.000Z (about 2 years ago)
- Last Synced: 2024-11-15T13:48:03.554Z (about 1 month ago)
- Topics: go, golang, mqtt
- Language: Go
- Homepage:
- Size: 104 KB
- Stars: 25
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pakhshi
![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/snapp-incubator/pakhshi/lint.yaml?label=lint&logo=github&style=flat-square&branch=main)
![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/snapp-incubator/pakhshi/test.yaml?label=test&logo=github&style=flat-square&branch=main)
[![Go Reference](https://pkg.go.dev/badge/github.com/snapp-incubator/pakhshi.svg)](https://pkg.go.dev/github.com/snapp-incubator/pakhshi)
[![Codecov](https://img.shields.io/codecov/c/gh/snapp-incubator/pakhshi?logo=codecov&style=flat-square)](https://codecov.io/gh/snapp-incubator/pakhshi)## 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](https://github.com/eclipse/paho.mqtt.golang) 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.
```go
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](https://github.com/anvari1313).