activemq-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Justin Bertram (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (ARTEMIS-1869) Cannot consume using STOMP a message published using MQTT
Date Wed, 23 May 2018 22:06:00 GMT

    [ https://issues.apache.org/jira/browse/ARTEMIS-1869?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16488096#comment-16488096
] 

Justin Bertram edited comment on ARTEMIS-1869 at 5/23/18 10:05 PM:
-------------------------------------------------------------------

Thanks for the code, [~lionel.cons]. I was able to reproduce what you're seeing in the Artemis
test-suite, and I believe I understand what's happening. Artemis follows the same general
pattern as ActiveMQ 5.x in regards to message types and STOMP which is:
 * If the message has a content-length header treat it as a bytes message
 * If the message doesn't have a content-length header treat it as a text message

For Artemis, this is outlined in the documentation in the "Stomp and JMS interoperability"
section of the [Protocols and Interoperability chapter|https://activemq.apache.org/artemis/docs/latest/protocols-interoperability.html].
For ActiveMQ 5.x this is outlined in the "Working with JMS Text/Bytes Messages and Stomp"
section of the [STOMP wiki article|http://activemq.apache.org/stomp.html]. More specifically,
the Artemis documentation also states that text messages (i.e. ones without a content-length
header) will have a "single nullable SimpleString in the body buffer."

Messages from MQTT are always treated as bytes messages because that's all the MQTT spec defines.

In your situation you're taking a bytes message from MQTT and changing it to a text message,
but you're not changing the body to have a single nullable SimpleString in the body buffer
which is what STOMP expects. When the STOMP implementation attempts to convert this message
into a STOMP frame it looks at the type and converts it appropriately. Since the message is
a text message it expects there to be a single nullable SimpleString in the body and it chokes
when there isn't and it can't send the message to the client.

Therefore, you can leave the message as a bytes message (which you indicate works fine and
also works fine in my tests) or you can change the message to a text message and ensure the
body buffer contains a single nullable SimpleString.  If you choose to do the latter then
I believe you can replace this code:
{code:java}
byte[] body = String.format("{\"value\":%d}", val).getBytes();
log.log(Level.INFO, String.format("buffer needs/capacity: %d/%d", body.length, buf.capacity()));
buf.clear();
buf.writeBytes(body);
{code}
with this:
{code:java}
log.log(Level.INFO, String.format("buffer needs/capacity: %d/%d", body.length, buf.capacity()));
buf.clear();
buf.writeNullableSimpleString(new SimpleString(String.format("{\"value\":%d}", val)));
{code}


was (Author: jbertram):
Thanks for the code, [~lionel.cons].  I was able to reproduce what you're seeing in the Artemis
test-suite, and I believe I understand what's happening.  Artemis follows the same general
pattern as ActiveMQ 5.x in regards to message types and STOMP which is:
* If the message has a content-length header treat it as a bytes message
* If the message doesn't have a content-length header treat it as a text message

For Artemis, this is outlined in the documentation in the "Stomp and JMS interoperability"
section of the [Protocols and Interoperability chapter|https://activemq.apache.org/artemis/docs/latest/protocols-interoperability.html].
 For ActiveMQ 5.x this is outlined in the "Working with JMS Text/Bytes Messages and Stomp"
section of the [STOMP wiki article|http://activemq.apache.org/stomp.html].  More specifically,
the Artemis documentation also states that text messages (i.e. ones without a content-length
header) will have a "single nullable SimpleString in the body buffer."

Messages from MQTT are always treated as bytes messages because that's all the MQTT spec defines.

In your situation you're taking a bytes message from MQTT and changing it to a text message,
but you're not changing the body to have a single nullable SimpleString in the body buffer
which is what STOMP expects.  When the STOMP implementation attempts to convert this message
into a STOMP frame it looks at the type and converts it appropriately.  Since the message
is a text message it expects there to be a single nullable SimpleString in the body and it
chokes when there isn't and it can't send the message to the client.

Therefore, you can leave the message as a bytes message (which you indicate works fine and
also works fine in my tests) or you can change the message to a text message and ensure the
body buffer contains a single nullable SimpleString.

> Cannot consume using STOMP a message published using MQTT
> ---------------------------------------------------------
>
>                 Key: ARTEMIS-1869
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-1869
>             Project: ActiveMQ Artemis
>          Issue Type: Bug
>            Reporter: Lionel Cons
>            Priority: Major
>         Attachments: TestTransformer.java
>
>
> I have a test MQTT producer that sends a message to an address. There is a queue bound
to this address and I can see the message using the web console. Message count is 1.
> I have a test STOMP consumer subscribing to this queue. It does not get the message.
> If I then start a STOMP publisher to send a message to the same address. The message
appears in the same queue. Message count is now 2.
> I then start again the STOMP consumer and it does get the STOMP published message (and
message count goes down to 1) but it does not get the MQTT published message. Why?



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message