Can two different MQTT brokers communicate with each other? - protocols

I am currently exploring the possibility of using MQTT protocol in my program and the system has found out that there are several different MQTT Brokers. So, my question is that can you mix and match brokers for this communication? For instance, Mosquitto broker on device 1 and ActiveMQ Broker on device 2. Will this work?

I think there might be a slight misunderstanding here.
In a simple deployment there would only be 1 MQTT broker that multiple MQTT clients (on one or many devices) would connect to this one broker and exchange messages on any topics. As long as all the client conforms to the MQTT specifications then they should be able to connect successfully to any broker implementation.
If you want a more complex deployment then it is possible to have multiple brokers and have groups of clients connect to different brokers. You can then set up what is known as a bridge between the brokers which allow the to share some/all of the topics. This allows messages to be shared by all clients regardless of which broker they connect to.
Assuming all the brokers conform to the MQTT spec (which is very likely) then it all should just work, but how you configure bridges differs between broker implementation.
Be aware that a new version of the MQTT spec (v5) just went live (end of 2017), brokers and client libraries will be updating to support this over the coming weeks/months. So check what versions you try and connect with.

Usually there's a bridge mode to connect brokers together, even for different kind of brokers such as Mosquitto and ActiveMQ, this is not only a concept in MQTT brokers but also in other message queue. Also, some kinds of brokers support with clustered, such as RabbitMQ. Official Mosquitto only support bridge, but there's a clustered mosquitto implementation on hui6075/mosquitto-cluster, it is easy to deploy.
Besides, the most significant different with "cluster" and "bridge" is that with clustered, the whole brokers looks like one logic broker for external clients, such as session, retain, qos, etc.

Related

jvm-libp2p how to achieve programs communicating over pubsub on the level of go-ipfs or js-ipfs nodes?

if we connect two jvm-libp2p hosts to a public ipfs node and send pubsub messages between them - messages are not passed
only if we connect them directly they receive each other's pubsub messages - but this defies the purpose of pubsub
however - with js-ipfs or go-ipfs running two or more peers and subscribing to a topic is enough to almost instantly have message exchange between them, even if isolated with no mDNS - so that it is clear that messages go through IPFS network and remote peers
how to achieve the same on jvm?

How to make two NODE.js servers communicate each other over RabbitMQ?

I wanted to create two servers in Node.js and make full-duplex communication with each other over rabbitMQ. I am new to messagebrokers or event-driven development, I just want to make one server serve API to the front-end another one just a chat server? Is that even a good approach?
Working directly with a broker is a bad idea. Typically, a gateway is added between the clients and the broker as an abstract layer. In this case, it will be easier for you to change the broker (for example, from rabbit to kafka, etc.), and you do not need to copy the client <-> broker logic in different languages. As example I just add this link reddwarf. Simple demo service is service and client is client

Does MQTT protocol support database?

As we know MQTT have using subscribe/publish method. May i know what platform user can save the database using MQTT protocol. Its hivemq or mosquito support database so i can see previous data recorded from the sensor?
If MQTT can support database. What other method beside using apache webserver.
MQTT is a Pub/Sub protocol, it is purely for delivering messages. What happens to those messages once delivered is not the concern of the protocol.
If you want to store all messages then you are going to need to implement that yourself.
This is either as:
A dedicated client that will subscribe to # and then store the messages to a database.
Some brokers have a plugin API that will allow you to register hooks that can intercept every message and store that to a database.
You will have to research if any broker you want to use supports plugins of this nature.

Routing MQTT protocol to PM2

We have some sort of devices connected to a MQTT Broker (mosquitto), publishing some events. We want to capture all these events through a node application. One simple solution is to create a node app as a client which is connected to MQTT Broker and listen for every event and do an specific job for them. But in scalability point of view, if we want to scale our node app, we have to run multiple instance of our node app and use a PM2 as a load balancer. But the problem is when we create more than one instance, all instances receive the same event and for that specific event, all instances do the same job multiple time as the number of instances we have.
How can we route all MQTT events to PM2 load balancer?
You are possibly approaching the problem the wrong way.
You want to look at something called Shared Subscriptions. This is new in the MQTT v5 specification (though some brokers implemented a propitiatory versions at MQTT v3).
Shared Subscriptions tells the broker to distribute in coming messages to collection of clients, only delivering each message to 1 of the group.
Mosquitto added support for Shared Subscriptions at version 1.6 (but you should make sure you are using the latest 1.6.x release)

MQTT and ActiveMQ communication

Background
I am very new to MQTT and ActiveMQ. I am trying to learn about both technologies, but their integration using Node.js is not clear.
Objective
The objective here would be to use MQTT with node, and then use ActiveMQ's broker.
Questions
If I publish a message on a MQTT topic then how I can transfer that message to an ActiveMQ queue?
If I have a MQTT topic named "Foo", does ActiveMQ need to have a queue named "Foo"?
Does Node.js support the MQTT protocol?
After publishing a message in a MQTT topic with content "Foo" using Node.js, how I can retrieve it from an ActiveMQ queue?
EDIT
My MQTT is running on a different server so I have added the below activemq.xml file. However, after adding it activemq gives me the following error on startup:
<transportConnectors>
<transportConnector name="mqtt" uri="tcp://<myhostname>:1883? maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
So how can I get the message published on MQTT topic in activemq queue?
Do I need any other configuration or do I need to first subscribe to a MQTT topic using java or any other technology and then push that message on ActiveMQ queue? Or ActiveMQ it does automatically?
By using compositeTopic in ActiveMQ configuration (activemq.xml).
No, ActiveMQ has a topic named FOO used by MQTT.
No, but there are extensions to Node.js which supports MQTT.
By using compositeTopic (see #1).
What do you mean by "My MQTT is running on different server"?
If you want a clustered things, you should use networkConnector instead of transportConnector.
If you want ActiveMQ to accept MQTT connection, simply change the protocol from uri="tcp://<myhostname>:1883?maximumConnections=1000&wireFormat.maxFrameSize=104857600" to "mqtt://<myhostname>:1883?maximumConnections=1000&wireFormat.maxFrameSize=104857600"

Resources