How to send ActiveMQ VirtualTopic in node js? - node.js

How to send ActiveMQ VirtualTopic in node js ?
Am using stompit library for send and receive queue.
This will working properly.
I need to send virtual topic, How to implement in node ?
ActiveMQ.Advisory.Producer.Topic.VirtualTopic
ActiveMQConnectionFactory allow to create producer and topic in java
But, there is no option like that in node js.
https://i.stack.imgur.com/o5tqE.png
If I produce from Java then
Topic: Lenovo.* (marked red color in screen shot)
then automatically created ActiveMQ.Advisory.Producer.Topic.Lenovo.*
(Marked green color in screen shot)
Not create ActiveMQ.Advisory.Producer.Topic when produce from node

Virtual destinations are just named endpoints like any other. To send to one the client would send to a destination like '/topic/VirtualTopic.Orders' and then consume from the queue '/queue/Consumer.A.VirtualTopic.Orders' and that is about it. See the documentation for the Virtual Destinations feature in ActiveMQ to understand how the naming works.

Related

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)

Suggestion for message broker

I need some help when choosing for message broker(RaabitMQ, Redis, etc) or other right tools for this situation.
I am upgrading my game server. It is written by Node.js. it consist of several process, i.e. GameRoom, Lobby, Chat, etc. When a user make request, the message will be routed to relevant process to process it. I do this by routing by my code and each process communicate with each other by node-ipc. However, this is not too efficient and is not scalable. Also, some process has very high work load(Lobby as many requests are related to it), we create several process of Lobby and route message randomly to different process of Lobby. I think message broker can help in this case and also I can even scale up by putting different process in different physical servers. I would like to know which message broker is suitable for this? Can a sender send a message to a queue which multiple consumers compete for a message and only one consumer consume it and reply the message to the sender? Thanks.
I'm not going to be able to talk about Kafka from experience, but any message-queue solution, as will RabbitMQ and ActiveMQ will do what you need.
I assume you're planning a flow like so:
REST_API -> queue -> Workers ----> data persistance <--------+
| |
+------> NotificationManager ----> user
The NotificationManager could be a service that lets the user know via Websockets or any other async communication method.
Some solutions will be better put together and take more weight off your shoulders. Solutions that are not just message-queues but are also task-queues will have ways with getting responses from workers.
Machinery, a project that's been getting my attention lately does all of those , whilst using MongoDB and RabbitMQ itself.

Moving Mail Messaged with Spring Integration

I 'm doing mail processing with spring-integration. I got the receiving part working, but I would like to move the messages to different folders after processing.
Unfortunately, the MimeMessages received from the Adapter are not 'real' javax.mail.Message, but an IntegrationMimeMessage (in AbstractMailReceiver)
Is there a way to access the 'javax.mail.Message' so that I can move them with plain JavaMail? Or does spring-integration provide an adapter that can move messages ? Could not find any in the documentation.

Unable to read Azure IoT hub MQTT subscription message data

I have successfully connected my ESP8266 Arduino project to the Azure IoT hub by following the steps outlined here:
https://azure.microsoft.com/en-gb/documentation/articles/iot-hub-mqtt-support/
The MQTT library that I am using is the following library:
https://github.com/Imroy/pubsubclient
Using the code I have been able to publish events to azure. The problem starts when trying to read the messages that are passed to the device.
Here is the code:
http://pastebin.com/7AVLQfFh
When I sue the Azure Device Explorer to send a message to the device the I get the following results:
As you can see the payload length is the same as the number of characters in the message but the characters are not the same. And also if I vary the string sent then the vales in the result are the same.
As a sanity check I have tried the code against a different MQTT service (Adafruit IO) and the results are as to be expected (here the message is 'ON' or 'OFF'):
The Azure MQTT service must be doing something different when it sends the messages to the device, what I needs to know is what it does differently.
Just a couple of hours ago I managed to get the messages flowing from Azure IoT hub to my ESP8266 using the original PubSubClient - link here. You are using the fork of that library that has been made more object oriented and probably has more enhancements.. but if you aren't very hooked on using the newer version I'd recommend getting the original one and trying it out.
I have my code on github if you need some reference: link
One important mention: the PubSubClient.h needs changing the #defineMQTT_MAX_PACKET_SIZE 128 to #defineMQTT_MAX_PACKET_SIZE 256 or more if you work with big packets
Also, I haven't tried to send any messages so I don't know how that'll work.
Update: I've also written a short blog post on how to set it up: link
According to this documentation page, property_bag is RFC2396 encoded.
RFC 2396-encoded(<PropertyName1>)=RFC 2396-encoded(<PropertyValue1>)&RFC 2396-encoded(<PropertyName2>)=RFC 2396-encoded(<PropertyValue2>)…
But isn't ABCD the same in plain text vs URI encoded you ask... Well, yes.
Install stunnel (https://www.stunnel.org/index.html), open a TLS 1.2 connection to IoT Hub on 8883/TCP and then point MQTT.fx or Paho to it and sniff the traffic with Wireshark, see what you get.
I was able to read all messages in plain ASCII text while talking to IoT Hub over REST, so whatever this is i think it's MQTT specific.
If you haven't done so already you should open an issue on their GitHub. They seem to be quite responsive: https://github.com/Azure/azure-iot-sdks/issues

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