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"
Related
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.
Is possible node.js interaction with JMS queue ? Context I need to implement a solution that needs a JMS and node to work, a can make a communication happen via java, but I want to know if it is possible to do it via node directly ?
The answer to your question will depend on which JMS broker you use. If your JMS broker also supports STOMP then you can use the node-stomp client. For example, both the ActiveMQ 5.x and ActiveMQ Artemis brokers support STOMP & JMS.
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)
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.
I' m using a MQTT publisher, RabbitMQ and a Mqtt subscriber. I have installed on RabbitMQ the plugin for to label the messages with timestamp (rabbitmq_message_timestamp).
I have built an AMQP Publisher, an AMQP Subscriber and a MQTT Subscriber using node.js and a MQTT Publisher using Node-Red (and the MQTT out block) setting the topic to test the server url, username and password of RabbitMQ user, retain=true and no QoS.
1st PROBLEM) When I use an AMQP Publisher and an AMQP Subscriber, i can retrieve (side Subscriber) the RabbitMQ's timestamp by reading the field with path: msg.properties.timestamp. But when I use a MQTT Publiher and a MQTT subscriber, if I try to retrieve the value of msg.properties.timestamp, the nodejs windows says that field "properties" is undefined.
2nd PROBLEM) When I public message with my Node-Red MQTT Publisher (with topic "test") if a MQTT Subscriber is running on test queue, it downloads the messages, but if there isn't any Subribers on test queue, the RabbitMQ console says that test queue is empty. After stopping the MQTT pUblisher, if I try to connect the MQTT Subscriber to test queue, it will receive only the last message.
Can anyone help me to solve these problems?
There is no where in a MQTT message to store the additional meta data properties (such as the timestamp you mention).
MQTT message headers pretty much just hold the topic, QOS and a retained flag.
So if you subscribe with the Node-RED MQTT client node that is the only meta data that will be available.