Results 1 to 10 of 11

Thread: JMS Adapter: Content Based Filtering

Hybrid View

  1. #1
    Join Date
    Feb 2012
    Posts
    6

    Question JMS Adapter: Content Based Filtering

    Environment: Websphere MQ 7.1 / Spring Integration 2.1.1-BUILD-SNAPSHOT

    Is there a way to configure a "jms:message-driven-channel-adapter" to enable content-based filtering with publish/subscribe?

    Without using Spring Integration / Websphere MQ, and relying on ZeroMQ, it is as easy as:

    Code:
        byte [] messageType = { 10, 2, 81, 84 };
        subscriber.subscribe( messageType );
    Would appreciate a way to do it with SI's help.

    P.S. The idea is not to route messages based on the payload in the same process / JVM, but to have many processes / JVMs running listening to only their messages from a single queue.
    Last edited by spinter; Feb 21st, 2012 at 03:36 PM. Reason: fixed the content based filtering link

  2. #2
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    You can add a MessageSelector via the "selector" attribute on a message-driven-channel-adapter element. Is that sufficient for your use-case?

  3. #3
    Join Date
    Feb 2012
    Posts
    6

    Arrow

    Mark,

    Thanks for the idea. Doing that is not horrible, but it also means if a source has a million messages in a queue, every subscriber would receive a million messages, and then will filter them out.

    If a "message selector" is the only choice I have with SI, can I use it to inspect a JMS header as well? I have control over where publishers will place a "selection criteria", and it would be nice if I can use JMS header for that, so I don't have to peek inside the payload. (I would still like to strip out all the JMSsness from the message before it is passed down the line)

    Thank you.

  4. #4
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,017

    Default

    I suppose it depends on your broker; a few googles for IBM MQ would indicate the selection is done on the broker. It's probably reasonable to expect that all enterprise-ready brokers will run the selection on the broker rather than the client.
    Last edited by Gary Russell; Feb 21st, 2012 at 10:19 PM.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  5. #5
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,017

    Default

    And, yes, the selection uses headers; in fact the JavaDoc for Message says...

    Message selectors cannot reference message body values.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  6. #6
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    I actually meant that you can use a JMS MessageSelector (not a Spring Integration filter), so that happens broker-side. In terms of the supported queries, scroll down to "Message Selectors": http://docs.oracle.com/javaee/1.3/ap...s/Message.html

  7. #7
    Join Date
    Feb 2012
    Posts
    6

    Arrow

    Gary, Mark,

    Right, I thought you meant an SI MessageSelector at first, since it is not immediately obvious where a "selector" attribute of "jms:message-driven-channel-adapter" points to. I did a quick "Command + F" on docs, and this particular "selector" is not (yet) discussed there.

    Now as I looked at it a bit closer I can see it takes a selector, passes it to JmsTemplate and:
    Code:
      protected Message doReceive(Session session, Destination destination, String messageSelector) throws JMSException {
    
        return doReceive(session, createConsumer(session, destination, messageSelector));
      }
    which goes directly to the broker.

    Just to confirm:

    Code:
        <jms:message-driven-channel-adapter destination="xyzQueue"
                                            channel="xyzPipe"
                                            selector="someId = '75D938E89AF18C30'"/>
    Will only receive messages that have "someId" set to "75D938E89AF18C30" in JMS header?

    Thank you.

  8. #8
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,017

    Default

    Almost; you can't add arbitrary 'headers', these are more properly called 'properties'. You can set arbitrary properties on messages that can be used in message selectors.

    http://publib.boulder.ibm.com/infoce...c/ac24876_.htm

    and

    http://docs.oracle.com/javaee/1.4/tu...4.html#wp79281

    (Scroll down the Message Headers and Message Properties).

    Please open up a documentation Improvement JIRA on the reference manual here...

    https://jira.springsource.org/browse/INT

    There *is* brief documentation in the XSD schema...

    Code:
    <xsd:attribute name="selector" type="xsd:string">
    	<xsd:annotation>
    		<xsd:documentation>
    A JMS Message Selector expression.
    		</xsd:documentation>
    	</xsd:annotation>
    </xsd:attribute>
    ...but we should explain it in the reference.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •