How to receive message published on a topic using mqtt protocol in spring:jms application? - spring

I am new to activemq.
I have a publisher which publish a message to a topic using mqtt protocol. And now I want to write a subscriber using Spring + JMS which will listen for the message on that topic.
I have following questions:
1) Can I have a same topic if I write the subscriber using tcp protocol.I mean to say, publisher will use MQTT to publish on a topic and subscriber will listen on that topic using TCP broker URL.
2) If above is not possible then how can I write a subscriber using spring + jms that will listen and receive the messages published on the topic using mqtt ?
Thank you in advance.

Did you even try? Yes, it works pretty much as you expect it to. MQTT msgs gets converted to JMS if you try read it with JMS (OpenWire).
From web site:
Message transformations
MQTT messages are transformed into an JMS
ByteMessage. Conversely, the body of any JMS Message is converted to a
byte buffer to be the payload of an MQTT message.

Related

IBMMQ push subscription : Is there a way in springboot/quarkuks/other to use push subscription? Not polling

Push-subscription
Is there a way in springboot or quarkus (or other framework) to consume messages from IBMMQ using push-subscription. I.e Not polling every minute to see if message exists.
Need not be JMS api.
The DefaultJms... in springboot is polling 1000x times more than the actual messages per day. It is not behaving as ' listener waiting for message push'
You could consume messages from IBM MQ using vert.x's AMQP client. This is a reactive toolkit that will give you an easy way of communicating with IBM MQ using the AMQP channel. Vert.x's AMQP client listens and reacts for push from IBM MQ.

How to automatically read/receive message from solace queue when application started?

I want to automatically read/receive messages from solace queue/topic if any message produced or published when my application is up. So is there any method in solace which can open connection automatically if there is any message available in Queue/Topic.
So is there any method in solace which can open connection automatically if there is any message available in Queue/Topic
This is not possible for JMS.
JMS applications initiate a connection to the broker and receive messages over the locally initiated connection.
The only way to do what you want is to use REST instead of JMS.
When a REST consumer is configured, the Solace event broker will initiate a HTTP connection to the application.
A sample can be found here:
https://solace.com/samples/solace-samples-rest-messaging/publish-subscribe/

Can we send messages between two clients using different protocols(STOMP - TCP) with ActiveMQ?

I have a scenario , where i have my sender code written in Node.js which uses STOMP protocol to publish it to the destination(queue) and the receiver code written in java which use TCP protocol to receive the message from the destination(queue) through ActiveMQ server.Will it be possible for the clients(sender/receiver) to communicate? or it should be the same protocol at either end?
The ActiveMQ documentation covers this on the Stomp page (http://activemq.apache.org/stomp.html) in the paragraphs
Working with JMS Text/Bytes Messages and Stomp
Message transformations
Stomp extensions for JMS message semantics
ActiveMQ extensions to Stomp
ActiveMQ supports richt message conversion between messages from different protocols. Not all multi-protocol have this feature, for example ActiveMQ Apollo (issue 267).
Not an issue. ActiveMQ acts as a multiprotocol message exchange so messages received by the broker in any supported protocol can in turn be sent to receivers in any other supported protocol.

How to Produce from MQTT and consume as MQTT and JMS in ActiveMQ

I have a setup where messages are produced as MQTT to ActiveMQ.
I have two consumers one as JMS and another MQTT.
When I am publishing message as JMS Message to the topic "foo", I am receiving the messages at both JMS and MQTT consumers, but when I am publishing as MQTT on the same topic I receive the message only on MQTT consumer and nothing at all is received at JMS consumer.
Is there something I need to do specifically when publishing as MQTT to be able to consume as MQTT as well as JMS.
Please help.
Update :
JMS Consumer
JMS Producer
MQTT Publisher
MQTT Subscriber
activemq.xml
Your problem looks to be that your JMS consumer is expecting the messages to arrive as a TextMessage which is a false assumption when dealing with MQTT produced messages.
MQTT messages are binary with no content type information or headers to define the payload. For that reason the broker will always interpret them as a BytesMessage and dispatch them as such. You will need to code for that fact and consume BytesMessage as well, and then read the payload out as a String.

AMQP & Openwire - Activemq broker and 2 different consumers

I have an activeMQ broker that supports both amqp and openwire.
Is it possible that a producer of openwire (tcp, port 61616) will produce to a queue that have a consumer that uses amqp protocol instead?
or am i limited to the same protocol consumers&producers only?
Yes, it is possible to interoperate with the OpenWire JMS client and an AMQP client using ActiveMQ. The destinations that hold the messages are not separate spaces therefore message place on a Queue by a client of one type are consumable by a client from some other protocol.
The only thing that you have to contend with is how the actual messages are conveyed to each client. ActiveMQ provides a configurable transfomer that can either preserve the original bytes of the AMQP message when sent from an AMQP client or transform that message into a more JMS style message object that would be received by the OpenWire client as the expected type (TextMessage, BytesMessage, MapMessage...).
Refer to the documentation of ActiveMQ for help in configuration and in understanding the mappings of AMQP to OpenWire messages.
http://activemq.apache.org/amqp.html
If you want to easiest to handle scenario where messages are transformed and always arrive at the OpenWire client as proper JMS types choose the JMS Transformer in configuration like so:
<transportConnector name="amqp" uri="amqp://localhost:5672?transport.transformer=jms"/>

Resources