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

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.

Related

How can i send a message to disconnected customers with spring kafka?

I can not send messages to disconnected clients.
I use spring boot with apach kafka as a message broker.
If you assign a consumer group id to a user's inbox, then the consumer protocol will read from the last unread message automatically until you commit the consumed offset back to Kafka
Kafka persists messages itself and consumers are not required to be online to receive events sent immediately from producers

Is It possible if i have put message to ActiveMq jms and consume it from RabbitMq jms?

I am new to jms,
I have did poc of spring jms with ActiveMq. In which I am producing messages in queue and consume it using consumer and one poc in which I am using spring jms with rabbitmq with producer and consumer and have added plugin of jms in rabbit mq to use spring jms with rabbitmq.
Is it Possible if I put Produce message in active MQ and Consume that messages using spring jms rabbitmq consumer?
Is It possible if yes then How?
Thanks in advance.
ActiveMQ and RabbitMQ are two different brokers - why do you need (and why do you think it's possible) to send messages to one broker and receive them from another?
You would need another application to move the messages; it's not clear why you would want to do that.
Typically, you would need an adapter layer to move the JMS messages from one MQ to another (i.e., active MQ to Rabbitmq etc.).
You can look here for some notes (IBM specific) on JMS adapters, but the underlying concept is the same i.e., consuming from one MQ and producing the messages to another MQ.

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 receive message published on a topic using mqtt protocol in spring:jms application?

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.

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