Announcement Announcement Module
No announcement yet.
Custom MessageSelector and DefaultMessageListenerContainer Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Custom MessageSelector and DefaultMessageListenerContainer

    Hi all,

    I'm having a quite strange problem to solve:

    I'm using the new DefaultMessageListenerContainer (org.springframework.jms.listener.DefaultMessageLi stenerContainer) for receiving messages from a Websphere MQ queue.

    As I only want to get specific messages out of this queue, I have to use message selectors. Before I've used the ListenerContainer, I've setup a test class, which receives the messages using the standard JMS template receiveSelected method. Within that test I've seen, that I have to setup the correlation ID in a quite strange way, as Websphere MQ has some strange format for communicating with a native C++ MQ client.

    The way I'm calculating the hex ID is done like this (got the advice from a Websphere MQ forum):
    private String setupHexCorrelId(String string)
            String filter = null;
            byte[] correlBytes = string.getBytes();
            StringBuffer fBuf = new StringBuffer("JMSCorrelationID = 'ID:");
            for (int i = 0; i < MQC.MQ_CORREL_ID_LENGTH; i++)
                if (i >= correlBytes.length)
                    byte b = correlBytes[i];
                    String hexStr = Integer.toHexString(b);
                    // -ve values produce 8 char results
                    if (hexStr.length() > 2)
                        hexStr = hexStr.substring(hexStr.length() - 2);
                    // small values produce 1 char results
                    if (hexStr.length() < 2)
            filter = fBuf.toString();
            return filter;

    Now the question is: how can I set this correlation ID to the DefaultMessageListenerContainer?

    The container is setup in the configuration and started by the Spring container:

    	<bean id="messageListenerContainer"
    		<property name="connectionFactory" ref="myConnectionFactory"/>
    		<property name="destinationName" value="queue:///test"/>
    		<property name="messageListener" ref="myMessageListener"/>
    		<property name="messageSelector" value="??????"/>
    How can I calculate the messageSelector in a method instead of setting it hardcoded to the property?

    Thanks in advance.


  • #2
    Custom MessageSelector and DefaultMessageListenerContainer


    My application sends a request for processing to a system which processes our requests and posts a response on a Topic. The response can be identified by the request id of the request send. We are right now using Spring 1.2.6 JMS and explicitly setting our message listener and setting the message selector when listening on the Topic.

    We not have to migrate the code to Spring 2.0 and make use of the MDP(s). I have been able to set up the Message Listener container but face the same issue as yours. I want my applications to be notified only for responses which correspond to requests send by it. So I have to set the message selector dynamically.

    I have not been able to find a solution for this. Did you find a solution to this issue?

    In case you have, please either post a reply to this posting or send me an email ar [email protected].

    Regards, Vishal