How to use JMS Message Transformation in ActiveMQ using Stomp / JSON

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

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

The format of the JSON objects I submit (in fairly printed form) is similar to the following:

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

Messages arrive in the message queue, but with the transform-error property set to "msg: msg".

+6
json activemq stomp
source share
2 answers

you can use any JSON notation for jms-object-json conversions if XStream can handle it. You can see sample tests for some examples. There we use the 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 by the following JSON

{"POJO": {"Name": "Dejan", "City": "Belgrade"}}

You can try using the same approach for your classes.

Hope this helps, Dejan

+3
source share

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

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

This is the same format as in the discussion forum. This format is a map object name / value pairs in java.

Selectors can only be used in properties and headers.

+4
source share

All Articles