How to use JMS Message Transformation in ActiveMQ with Stomp/JSON
Asked Answered
C

3

6

I am sending messages in JSON format to an ActiveMQ server. I am trying to use JMS Transformation to transform the JSON encoded object into a true Java Object in hopes of being able to use selectors on the data inside.

Here is a link to the documentation on Stomp and Message Transformation. Here is a link to a discussion on the patch where someone shows an example of a legal JSON object

The format of the JSON objects I am sending (in pretty print) are similar to this:

{
   "msg": {
      "flag1" : "value1",
      "flag2" : "value2"
   }
}

The messages arrive in the message queue, but with the transformation-error property set to 'msg : msg'.

Chrysa answered 31/12, 2008 at 10:8 Comment(0)
A
3

you can use any JSON notation for your jms-object-json transformations as long as XStream can handle it. You can take a look at test cases for some examples. There, we use SamplePojo class:

https://svn.apache.org/repos/asf/activemq/trunk/activemq-stomp/src/test/java/org/apache/activemq/transport/stomp/SamplePojo.java

which is properly annotated so it can be represented with the following JSON

{"pojo":{ "name":"Dejan", "city":"Belgrade" }}

You can try using the same approach for your classes.

Hope this helps, Dejan

Automat answered 5/1, 2009 at 12:16 Comment(1)
it should be working now, but I do not know if this still applies or if there is a better method now.Chrysa
C
5

The only format accepted by the transformation jms-map-json or jms-object-json is a simple Map format, which in JSON is:

{"map" : 
  {"entry" : 
    [ 
      { "string1": [ "key1", "value1" ] },
      { "string2": [ "key2", "value2" ] }
    ]
  }
}

This is the same format shown in the discussion forum. This format represents a name/value pair map object in java.

Selectors are only usable on Properties and Headers.

Chrysa answered 31/12, 2008 at 11:52 Comment(0)
A
3

you can use any JSON notation for your jms-object-json transformations as long as XStream can handle it. You can take a look at test cases for some examples. There, we use SamplePojo class:

https://svn.apache.org/repos/asf/activemq/trunk/activemq-stomp/src/test/java/org/apache/activemq/transport/stomp/SamplePojo.java

which is properly annotated so it can be represented with the following JSON

{"pojo":{ "name":"Dejan", "city":"Belgrade" }}

You can try using the same approach for your classes.

Hope this helps, Dejan

Automat answered 5/1, 2009 at 12:16 Comment(1)
it should be working now, but I do not know if this still applies or if there is a better method now.Chrysa
R
0

It should be mentioned that ActiveMQ version must at least 5.8, because with 5.6 version I had problem when transformation just did not work.

Rackley answered 14/2, 2020 at 13:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.