camel-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Darrell King (JIRA)" <j...@apache.org>
Subject [jira] [Created] (CAMEL-9984) RabbitConsumer.stop() doesn't stop underlying AutorecoveringConnection obtained from supplied ConnectionFactory
Date Mon, 23 May 2016 12:54:12 GMT
Darrell King created CAMEL-9984:
-----------------------------------

             Summary: RabbitConsumer.stop() doesn't stop underlying AutorecoveringConnection
obtained from supplied ConnectionFactory
                 Key: CAMEL-9984
                 URL: https://issues.apache.org/jira/browse/CAMEL-9984
             Project: Camel
          Issue Type: Bug
          Components: camel-rabbitmq
    Affects Versions: 2.17.1
            Reporter: Darrell King
            Priority: Minor


If I have a ConnectionFactory defined as:
{code:borderStyle=solid}
ConnectionFactory connectionFactory = new ConnectionFactory();
connectionFactory.setAutomaticRecoveryEnabled(true);
connectionFactory.setUsername(username);
connectionFactory.setPassword(password);
{code}
And a Camel route defined like:
{code:borderStyle=solid}
rabbitmq://localhost:5672/MyExchange?connectionFactory=#connectionFactory&exchangeType=direct&queue=MyQueue&routingKey=MyRoutingKey
{code}
Performing these steps:
* Start my application and it connects to Rabbit and consumes messages
* Shutdown the RabbbitMQ server
* Shutdown my Camel application

The application doesn't stop fully because the automatic recovery mechanism has background
threads running. It carries on indefinately logging messages like:
{code:borderStyle=solid}
	at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:106)
	at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:102)
	at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:350)
	at com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnectionFactory.newConnection(RecoveryAwareAMQConnectionFactory.java:37)
	at com.rabbitmq.client.impl.recovery.AutorecoveringConnection.recoverConnection(AutorecoveringConnection.java:476)
	at com.rabbitmq.client.impl.recovery.AutorecoveringConnection.beginAutomaticRecovery(AutorecoveringConnection.java:444)
	at com.rabbitmq.client.impl.recovery.AutorecoveringConnection.access$000(AutorecoveringConnection.java:53)
	at com.rabbitmq.client.impl.recovery.AutorecoveringConnection$1.shutdownCompleted(AutorecoveringConnection.java:383)
	at com.rabbitmq.client.impl.ShutdownNotifierComponent.notifyListeners(ShutdownNotifierComponent.java:75)
	at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:578)
{code}
Looking at org.apache.camel.component.rabbitmq.RabbitConsumer.stop()
{code:borderStyle=solid}
    public void stop() throws IOException, TimeoutException {
        stopping = true;
        if (channel == null) {
            return;
        }
        channel.basicCancel(tag);
        try {
            channel.close();
        } catch (TimeoutException e) {
            log.error("Timeout occured");
            throw e;
        }
    }
{code}
The calls to channel.basicCancel(tag) and channel.close() both throw com.rabbitmq.client.AlreadyClosedException
when the server has closed the connection which stops the automatic recovery thread from being
halted. Checking whether the channel is open before the calls to channel.basicCancel(tag)
and channel.close() seems to fix the issue.
{code:borderStyle=solid}
    public void stop() throws IOException, TimeoutException {
        stopping = true;
        if (channel == null) {
            return;
        }
        if (tag != null && isChannelOpen()) {
            channel.basicCancel(tag);
        }
        try {
            if (isChannelOpen()) {
                channel.close();
            }
        } catch (TimeoutException e) {
            log.error("Timeout occured");
            throw e;
        }
    }
{code}

I'll submit a PR later



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message