« Return to Thread: Spring MessageListenerAdapter and invalid ReplyTo destination

Re: Spring MessageListenerAdapter and invalid ReplyTo destination

by Bryan Talbot :: Rate this Message:

Reply to Author | View in Thread

IIT Software wrote:
Actually you will receive an InvalidDestinationException (extends JMSException) if you try to send to a temp queue which has been deleted in the meantime. This exception will be thrown if you try to create a producer on it. However, deletion of such a temp destination is asynchronously and can happen any time, e.g. after the producer has been created and while it writes to the queue and before commit. In that case it is possible that you will get a simple JMSException.

I would catch InvalidDestinationException and would check the JMSRedelivered flag.
SwiftMQ doesn't seem to throw an InvalidDestinationException in this case -- I get a plain JMSException instead.  

Here's a simple straight JMS program to demonstrate this against SwiftMQ 7.4.1 (works the same with 7.3.2):


package com.age.jms;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.InitialContext;


public class InvalidDestinationSender
{
        public static final void main( String [] args )
            throws Exception
        {
        Connection connection = null;
            try
            {
            final String destinationName = args[0];
            final InitialContext jndiContext = new InitialContext();
            final ConnectionFactory cf = (ConnectionFactory)jndiContext.lookup( "ConnectionFactory" );
            jndiContext.close();

            connection = cf.createConnection();
            final Session session = connection.createSession( false, Session.AUTO_ACKNOWLEDGE );
            connection.start();
            System.out.println( "Createing queue named: " + destinationName );
            final Destination dest = session.createQueue( destinationName );
               
            // I don't expect this code to be reached when the destination is invalid
            final MessageProducer mp = session.createProducer( dest );
            final TextMessage msg = session.createTextMessage();
            msg.setText( "the hero you deserve" );
            mp.send( msg );
            }
            finally
            {
            if( null != connection )
            {
                connection.close();
            }
            }
        }
}



$> java -classpath bin:lib/swiftmq-7.4.1.jar:lib/jms.jar com.age.jms.InvalidDestinationSender noqueue
Createing queue named: noqueue
Exception in thread "main" javax.jms.JMSException: com.swiftmq.swiftlet.queue.UnknownQueueException: queue 'noqueue@router1' is unknown
        at com.swiftmq.jms.ExceptionConverter.convert(Unknown Source)
        at com.swiftmq.jms.v630.SessionImpl.createSender(Unknown Source)
        at com.swiftmq.jms.v630.SessionImpl.createProducer(Unknown Source)
        at com.age.jms.InvalidDestinationSender.main(InvalidDestinationSender.java:32)

 « Return to Thread: Spring MessageListenerAdapter and invalid ReplyTo destination