handle multiple mqtt server/cluster based on paho client

Overview

pakhshi

GitHub Workflow Status 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.

Issues
  • Implement a new token type

    Implement a new token type

    As the token type is returning the state of publishing or subscriptions, we need to define a new one that implements the Token interface and holds the state of each pub/sub on each broker.

    Maybe we decide not to return the error if at least one pub/sub be done successfully. I think it can be configurable and the user should be able to set it.

    opened by anvari1313 5
  • Separate go mods

    Separate go mods

    Separating go mods can remove unwanted dependencies for users who are using this client. The client just has a dependency on paho mqtt and others are used for the sample CLI application.

    Also maybe it's better to put the client package and token package in the root of the repo with the root go mod and create another go mod for the CLI application.

    enhancement 
    opened by anvari1313 0
Owner
Parham Alvani
Backend Developer, Ph.D. Student, Happy and Smiling
Parham Alvani
Vallox RS-485 MQTT gateway to integrate Vallox RS485 ventilation device to Home Assistant via MQTT.

Vallox RS-485 MQTT gateway to integrate Vallox RS485 ventilation device to Home Assistant via MQTT. Implements Home Assistant MQTT discovery but can also be used without Home Assistant.

Pekka Vainio 1 Dec 26, 2021
Sensirion SCD30 CO2 sensor MQTT gateway with Home Assistant MQTT discovery

Sensirion SCD30 CO2 sensor MQTT gateway for Home Assistant Overview This gateway can be used to publish measurements SCD30 to mqtt. It supports Home A

Pekka Vainio 0 Nov 2, 2021
Lg-ess-mqtt - MQTT Firmware Extension for 1st generation LG ESS BESS

lg-ess-mqtt This projects is a firmware extension for the 1st generation LG ESS

Steffen Vogel 0 Jan 10, 2022
IP Camera Alarm Server to MQTT

IP Camera Alarm Server Universal Alarm Server for all your IP cameras in one place! Integrates well with Home Assistant, Node-Red, etc. Runs great on

Toxuin 58 Aug 5, 2022
An embeddable lightweight Go/Golang MQTT broker(server) for IoT.

Snple MQTT 简体中文 Note: The API of this library is still unstable and has not been sufficiently tested, please do not use it in production environments.

null 8 Jun 1, 2022
MQTTtimer is based mqtt protocol sync timer

MQTTTimer is based mqtt protocol sync timer. You can used ntp sync time protocol in IoT without ntp server. used mqtt protocol sync time is tcp connne

hysios 8 Oct 27, 2021
Hermes is a tiny MQTT compatible broker written in Go.

Hermes Hermes is a tiny MQTT compatible broker written in Go. The goals of the project are as below Easy to compile, and run Tiny footprint Extensible

Chaitanya Munukutla 54 Feb 24, 2022
Generic Prometheus ⟷ MQTT Bridge

Promqtt: Prometheus ⟷ MQTT Bridge Promqtt makes Prometheus MQTT capable in a truly generic way. It has no assumptions on message payloads or topic lay

sh0rez 15 Apr 11, 2022
mqtt-rewriter is a tool that can forward data from a topic to another topic.

mqtt-rewriter Background mqtt-rewriter is a tool that can forward data from a topic to another topic. Install Todo... Usage Currently only supports tw

fissssssh 2 Feb 18, 2022
A robust and easy to use MQTT rule engine

⚙ MQTT COMMANDER A robust and easy to use MQTT rule engine Configure your MQTT Rules via easy to use YML Files Supports JSON encoded MQTT Messages Sup

Calvin Köcher 4 Jun 23, 2022
Send IR command through MQTT

Introduction This program can be used in two different modes: Either it is waiting for an id button on a MQTT topic and execute the corresponding LIRC

null 2 Dec 15, 2021
Simple BLE to MQTT gateway

BLE_to_MQTT_gw Simple BLE to MQTT gateway This app will scan for the Eddystone BLE advertisement packets from my ESP32 BLE sensor, and forward tempera

null 1 Dec 29, 2021
Smq - Simple MQTT Broker with golang

Simple MQTT Broker 关于 Golang MQTT Broker, Version 3.1.1, and Compatible for ecli

null 8 Jul 7, 2022
Dwarka - API gateway offers REST API to manage various device controlled using MQTT protocol

dwarka API gateway offers REST API to manage various device controlled using 'MQ

Krishnaswamy Subramanian 1 Jun 9, 2022
An extensive Philips Hue client library for Go with an emphasis on simplicity

Huego An extensive Philips Hue client library for Go with an emphasis on simplicity. It is designed to be clean, unbloated and extensible. With Huego

Amir Mofasser 211 Aug 2, 2022
A Go client for Google IoT Core

IoT A simple framework for implementing a Google IoT device. This package makes use of the context package to handle request cancelation, timeouts, an

Andrew Young 59 Jul 11, 2022
Server motherboard hardware monitoring

hardware-events This software helps with the monitoring of a server motherboard. The project started when I changed the FANs on a Supermicro motherboa

Fred 1 Jan 24, 2022
Golang DNSTAP sensor use to collect passive dns data from a recursive name server

dnstap-sensor DNSTAP-SENSOR is a Golang program that is used to collect passive dns data from a recursive name server and submit it to Deteque's DNSTA

Andrew Fried 1 Jan 18, 2022
Courier Golang client library provides an opinionated wrapper over paho MQTT library to add features on top of it

Courier Golang Client Library Introduction Courier Golang client library provides an opinionated wrapper over paho MQTT library to add features on top

Gojek 29 Aug 1, 2022
Gmqtt is a flexible, high-performance MQTT broker library that fully implements the MQTT protocol V3.1.1 and V5 in golang

中文文档 Gmqtt News: MQTT V5 is now supported. But due to those new features in v5, there area lots of breaking changes. If you have any migration problem

null 709 Aug 5, 2022
Vallox RS-485 MQTT gateway to integrate Vallox RS485 ventilation device to Home Assistant via MQTT.

Vallox RS-485 MQTT gateway to integrate Vallox RS485 ventilation device to Home Assistant via MQTT. Implements Home Assistant MQTT discovery but can also be used without Home Assistant.

Pekka Vainio 1 Dec 26, 2021
Sensirion SCD30 CO2 sensor MQTT gateway with Home Assistant MQTT discovery

Sensirion SCD30 CO2 sensor MQTT gateway for Home Assistant Overview This gateway can be used to publish measurements SCD30 to mqtt. It supports Home A

Pekka Vainio 0 Nov 2, 2021
Lg-ess-mqtt - MQTT Firmware Extension for 1st generation LG ESS BESS

lg-ess-mqtt This projects is a firmware extension for the 1st generation LG ESS

Steffen Vogel 0 Jan 10, 2022
ScriptTiger 17 Aug 7, 2022
cluster-api-state-metrics (CASM) is a service that listens to the Kubernetes API server and generates metrics about the state of custom resource objects related of Kubernetes Cluster API.

Overview cluster-api-state-metrics (CASM) is a service that listens to the Kubernetes API server and generates metrics about the state of custom resou

Daimler Group 58 Jul 23, 2022
MQTT client

mqttcli -- MQTT Client for shell scripting mqttcli is an MQTT 3.1.1 Client which has almost same options with mosquitto_pub/sub. However, it has addit

shirou 98 Jun 13, 2022
IP Camera Alarm Server to MQTT

IP Camera Alarm Server Universal Alarm Server for all your IP cameras in one place! Integrates well with Home Assistant, Node-Red, etc. Runs great on

Toxuin 58 Aug 5, 2022
An embeddable lightweight Go/Golang MQTT broker(server) for IoT.

Snple MQTT 简体中文 Note: The API of this library is still unstable and has not been sufficiently tested, please do not use it in production environments.

null 8 Jun 1, 2022
MQTTtimer is based mqtt protocol sync timer

MQTTTimer is based mqtt protocol sync timer. You can used ntp sync time protocol in IoT without ntp server. used mqtt protocol sync time is tcp connne

hysios 8 Oct 27, 2021