« Return to Thread: Spring MessageListenerAdapter and invalid ReplyTo destination

Spring MessageListenerAdapter and invalid ReplyTo destination

by Bryan Talbot :: Rate this Message:

Reply to Author | View in Thread

I have a stand-alone spring program (no J2EE container) listening on a queue and sending response messages to the destination in the ReplyTo header. The application is configured to use spring's MessageListenerAdapter and DefaultMessageListenerContainer.

Everything works fine until a message is received that has an invalid destination in the ReplyTo header. In my use case, the requester has disconnected (timeout) and the temporary destination created for reply has been closed by the router.

When this happens, the MessageListenerAdapter throws the JMSException back to the DefaultMessageListenerContainer which attempts to redeliver the problem message again -- this continues indefinitely.

This seems like a common use case. What is the best way to handle this condition?

I have a work-around but it is certainly not pretty. My work around involves sub-classing the MessageListenerAdapter and overriding the sendResponse() method to check for certain JMSExceptions. Unfortunately it looks like I have to check the exception's message string to see if it's an exception that should be ignored.

protected void sendResponse( Session session, Destination destination, Message response ) 
        throws JMSException 
    {
        try
        {
            super.sendResponse( session, destination, response );
        }
        catch( JMSException e )
        {
            if( e.getMessage().matches( "com.swiftmq.swiftlet.queue.UnknownQueueException: queue 'tmp\\$[^']+' is unknown" ) )
            {
                logger.warn( "Discarding response message - " + e.getMessage() );
                return;
            }
            throw e;
        }
    }

Thanks for any suggestions

-Bryan

 « Return to Thread: Spring MessageListenerAdapter and invalid ReplyTo destination