ExceptionListener delivered multiple times

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

ExceptionListener delivered multiple times

serega
Hello.
I have an application that connects to two or more SwiftMQ-9.5.0 routers using MessageListener API. I added an ExceptionListener to each QueueConnection to intercept the event when a connection/server is down and the swiftmq client transparent reconnect fails to reestablish a connection after reaching max-retries.  I tested the ExceptionListener with two swiftmq routers.  After the application started and connected to Swiftmq routers I shutdown on of the routers. A few minutes later I observed two exceptions in the log delivered to both ExceptionListeners associated with two different QueueConnections. The error message was the same in both cases indicating the IP address of the host on which I killed the router.  

2015-01-22 21:08:03,418 ERROR [SwiftMQ-ConnectorPool-3] jms.MultiQueueListenerContainer - Received exception on connection from smqp://us2labitpqueue002:4001/timeout=2000
com.swiftmq.jms.ConnectionLostException: Unable to connect to [[ServerEntry, hostname=10.250.0.126, port=4001]], max. retries reached!
        at com.swiftmq.jms.v750.ConnectionImpl.cancelAndNotify(Unknown Source)
        at com.swiftmq.jms.v750.Connector.visit(Unknown Source)
        at com.swiftmq.jms.v750.po.POHandover.accept(Unknown Source)
        at com.swiftmq.tools.pipeline.PipelineQueue.process(Unknown Source)
        at com.swiftmq.tools.queue.SingleProcessorQueue.dequeue(Unknown Source)
        at com.swiftmq.tools.pipeline.PipelineQueue$QueueProcessor.run(Unknown Source)
        at com.swiftmq.client.thread.PoolExecutor.run(Unknown Source)
2015-01-22 21:08:03,419 ERROR [SwiftMQ-ConnectorPool-6] jms.MultiQueueListenerContainer - Received exception on connection from smqp://us2labitpqueue001:4001/timeout=2000
com.swiftmq.jms.ConnectionLostException: Unable to connect to [[ServerEntry, hostname=10.250.0.126, port=4001]], max. retries reached!
        at com.swiftmq.jms.v750.ConnectionImpl.cancelAndNotify(Unknown Source)
        at com.swiftmq.jms.v750.Connector.visit(Unknown Source)
        at com.swiftmq.jms.v750.po.POHandover.accept(Unknown Source)
        at com.swiftmq.tools.pipeline.PipelineQueue.process(Unknown Source)
        at com.swiftmq.tools.queue.SingleProcessorQueue.dequeue(Unknown Source)
        at com.swiftmq.tools.pipeline.PipelineQueue$QueueProcessor.run(Unknown Source)
        at com.swiftmq.client.thread.PoolExecutor.run(Unknown Source)



There should be a correlation between QueueConnection, ExceptionListener and JMSException.  

Thanks,
Sergey.
Reply | Threaded
Open this post in threaded view
|

Re: ExceptionListener delivered multiple times

IIT Software
Administrator
So as far as I understand you get this exception on both routers although you only lost one connection?
Reply | Threaded
Open this post in threaded view
|

Re: ExceptionListener delivered multiple times

serega
That's right, and the routers are installed on different hosts.
The exception listener "knows" the router which it was associated with.   As I workaround I parse the message in the exception and extract the ip address, then I match this ip with the ip of the router, and if they don't match I ignore the exception.
Reply | Threaded
Open this post in threaded view
|

Re: ExceptionListener delivered multiple times

IIT Software
Administrator
We will verify it and fix it if necessary.
Reply | Threaded
Open this post in threaded view
|

Re: ExceptionListener delivered multiple times

IIT Software
Administrator
In reply to this post by serega
We have verified this and were not able to reproduce it.

Here is the test code:


import com.swiftmq.tools.concurrent.Semaphore;

import javax.jms.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Hashtable;

public class TestExceptionlistener2
{
  private static void newConnection(final String url) throws Exception
  {
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY,"com.swiftmq.jndi.InitialContextFactoryImpl");
    env.put(Context.PROVIDER_URL,url);
    InitialContext ctx = new InitialContext(env);
    QueueConnectionFactory connectionFactory = (QueueConnectionFactory)ctx.lookup("ConnectionFactory");
    ctx.close();
    Connection connection = connectionFactory.createConnection();
    connection.setExceptionListener(new ExceptionListener()
    {
      public void onException(JMSException e)
      {
        System.out.println(url+": "+e);
      }
    });
    System.out.println(url+" created");
  }
  public static void main(String[] args)
  {
    try {
      newConnection("smqp://localhost:7000");
      newConnection("smqp://localhost:8000");
      Semaphore sem = new Semaphore();
      sem.waitHere();
    } catch (Exception e)
    {
      System.out.println(e);
    }
  }
}


Started 2 routers, one on port 7000, the other on port 8000 (JMS).

Killed the first one:


./starter TestExceptionlistener2
smqp://localhost:7000 created
smqp://localhost:8000 created
smqp://localhost:7000: com.swiftmq.jms.ConnectionLostException: Unable to connect to [[ServerEntry, hostname=localhost, port=7000]], max. retries reached!


Restarting the first, killing the second router:


./starter TestExceptionlistener2
smqp://localhost:7000 created
smqp://localhost:8000 created
smqp://localhost:8000: com.swiftmq.jms.ConnectionLostException: Unable to connect to [[ServerEntry, hostname=localhost, port=8000]], max. retries reached!


So each ExceptionListener was only called once.