2 Replies Latest reply on Feb 14, 2012 2:13 PM by rodk

    How does a REST publisher specify a selector data field?

      For HornetQ Rest messaging, how do I specify the selector data value for

      the publisher?

       

      I want to use the HornetQ REST product for both publishing and subscribing, with the publisher providing a field called "category" that can be used in a message selector by the subscriber.

       

      Below is my subscription request (hand-edited to change the host name)

       

      <push-topic-registration>

        <link rel='push' href='http://some-host:8080/store' type='application/xml' method='POST' />

        <selector><![CDATA[category = 'B']]></selector>

      </push-topic-registration>

       

      I'm pretty sure that I got the subscriber registration correct.

       

      But for the publisher, I am confused how to specify category. The HornetQ Rest Interface Guide version 2.2.5 doesn't mention anything in Chapter 4 "Posting Messages" about specifying an identifier.

      The closest that I see is Chapter 5 "Consuming Messages via Pull" which says

      %%

      selector This is an optional JMS selector string. The HornetQ REST interface adds HTTP headers to the JMS message for REST produced messages. HTTP headers are prefixed with "http_" and

      every '-' charactor is converted to a '$'.

      %%

       

      So for my publisher, I specified a "category" and an "http_category" in the HTTP header with associated values, but the end result is that my subscriber  receives 0 messages. Apparently, the published message does not contain the field that I'm looking for.

       

       

      I know that the message selection is working, because when I specify

        <selector><![CDATA[category <> 'B']]></selector>

      then I receive every message.

       

      I am using HornetQ 2.2.5.

       

      Any hints? Any example code for the publisher?

       

      Thanks.

        • 1. Re: How does a REST publisher specify a selector data field?
          jbertram

          There currently is no support for specifying arbitrary message properties on a message published by a REST client.

          • 2. Re: How does a REST publisher specify a selector data field?

            It helped knowing that what I was looking for does not exist. Thanks!

             

            The workaround is to create an incoming topic and a JMS bridge between the REST publisher and REST subscribers.

             

            So a setup might look like this:

             

            REST publisher  ==>  incomingTopic  == push ==> JMS bridge (see note 1)  == publish ==> notifyTopic  == push ==> REST subscriber

             

            note 1: In this code,

            • a JMS client receives the message (HornetQ receives it as a ByteMessage... you'll have to convert it to a String to get to the original XML)
            • Create an ObjectMessage for the outgoing message. The message body is the original XML string.
            • Add properties, as appropriate (e.g., call Message's setStringProperty).
            • Per section 9.1 of the "HornetQ REST Interface 2.2.5.Final", set the property as follows: message.setStringProperty(org.hornetq.rest.HttpHeaderProperty.CONTENT_TYPE, "application/xml");
            • Publish the outgoing message
            • The REST subscribers should receive the messages per the filter settings when they subscribed