Tuesday, 25 May 2010

ActiveMQ Advisories and STOMP

Advisory Messages in ActiveMQ are pretty useful, but since I mostly use STOMP clients I never really knew how useful !  I was blocked by this so prompted by a mail from Gary Tully on the activemq-users list and a long weekend coming up I sat down and tried to work out just what was needed.  In the end, after a brief diversion into why JmsFrameTranslator isn't actually used in the server, I got a pretty simple implementation up and running.  This was aided by XStream already being a dependency and it having pretty good JSON support.  Some tests later and I have a first implementation.

The internal openwire DataStructure objects are now marshalled into the STOMP message body as JSON.  An example Advosiry sent to /topic/ActiveMQ.Advisory.Consumer.Queue.>:

{"ConsumerInfo": {
"commandId": 4,
"responseRequired": true,
"consumerId": {
"connectionId": "ID:pb-d-128-141-235-87.cern.ch-52535-1274794978077-4:1",
"sessionId": 1,
"value": 1
"destination": {
"@class": "ActiveMQQueue",
"string": "testConsumerAdvisory",
"null": {}
"prefetchSize": 1000,
"maximumPendingMessageLimit": 0,
"browser": false,
"dispatchAsync": true,
"noLocal": false,
"exclusive": false,
"retroactive": false,
"priority": 0,
"optimizedAcknowledge": false,
"noRangeAcks": false

The code supports automatically supports all command objects that could be marshalled. One little problem is how the "destination" object is marshalled. Not sure why we get the @class in there.

No comments: