Autorecovery Issue

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

Autorecovery Issue

Ranjitha Shet
Hi,

I am trying to use the autorecovery feature.. 


public ConnectToRabbitMq(String sServeltName, String sDeviceName, Object oStreamType) throws IOException {

        /* *****create a connection to the server/broker:******************/
        ConnectionFactory factory = new ConnectionFactory();

        factory.setAutomaticRecoveryEnabled(true);
      
        factory.setUsername(USERNAME);//the AMQP user name used when connecting to the broker
        factory.setPassword(PASSWORD);//the password used when connecting to the broker
        factory.setVirtualHost(VHOST);//the virtual host used when connecting to the broker
        factory.setHost(HOST);//connect to a broker on the local machine - hence the localhost.  
        factory.setPort(PORT);//the default port used for connections

        connection = factory.newConnection(); 
        channel = connection.createChannel();// data channel, opens channel
        
        /* *****create a connection to the server/broker:******************/

            /* ******declare que and exch******************/

            exchangeName = sDeviceName;
            queueName = new StringBuffer(sServeltName).append('_').append(exchangeName).toString();

            channel.exchangeDeclare(exchangeName, "topic", false, false, null); 
            channel.queueDeclare(queueName, false, false, true, null);

            /* ******declare que and exch******************/

            String replytoBindinKey = SOMEKEY;
            
            channel.queueBind(queueName, exchangeName, replytoBindinKey);

            consumer = new QueueingConsumer(channel);
            channel.basicConsume(queueName, true, consumer);

    }

What I am trying to do is.., 
I publish a message(request) to a particular exchange.., it goes to server and in server side.., based on request published and routingkey,, response is published from server side..
and I receive the response..

To publish I use  --> channel.basicPublish

and to receive message what I do is --> 

while(true){

QueueingConsumer.Delivery delivery = consumer.nextDelivery();
..
..
}

when I disconnect the network cable, say it gets disconnected when both receiving and publishing takes place.. (Message published and received are different messages(same exchange))
 I get the following message.

Caught an exception during connection recovery!
java.net.NoRouteToHostException: No route to host: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:519)
at com.rabbitmq.client.impl.FrameHandlerFactory.create(FrameHandlerFactory.java:32)
at com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnectionFactory.newConnection(RecoveryAwareAMQConnectionFactory.java:34)
at com.rabbitmq.client.impl.recovery.AutorecoveringConnection.recoverConnection(AutorecoveringConnection.java:388)
at com.rabbitmq.client.impl.recovery.AutorecoveringConnection.beginAutomaticRecovery(AutorecoveringConnection.java:360)
at com.rabbitmq.client.impl.recovery.AutorecoveringConnection.access$000(AutorecoveringConnection.java:48)
at com.rabbitmq.client.impl.recovery.AutorecoveringConnection$1.shutdownCompleted(AutorecoveringConnection.java:345)
at com.rabbitmq.client.impl.ShutdownNotifierComponent.notifyListeners(ShutdownNotifierComponent.java:75)
at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:572)
at java.lang.Thread.run(Thread.java:619)
and on connecting back.., if server side publish message to tat particular exchange.., wont receive any message in my application,, and I get this error

DefaultExceptionHandler: Consumer com.rabbitmq.client.QueueingConsumer@137d090 (amq.ctag-gl009sKgA7rr2PyKA1MxAS) method handleDelivery for channel AMQChannel(amqp://guest@localhost:5672/,1) threw an exception for channel AMQChannel(amqp://guest@localhost:5672/,1):
com.rabbitmq.client.ShutdownSignalException: connection error
at com.rabbitmq.client.QueueingConsumer.checkShutdown(QueueingConsumer.java:172)
at com.rabbitmq.client.QueueingConsumer.handleDelivery(QueueingConsumer.java:124)
at com.rabbitmq.client.impl.ConsumerDispatcher$5.run(ConsumerDispatcher.java:140)
at com.rabbitmq.client.impl.ConsumerWorkService$WorkPoolRunnable.run(ConsumerWorkService.java:85)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.net.SocketException: Software caused connection abort: recv failed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read(BufferedInputStream.java:237)
at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:271)
at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:95)
at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:139)
at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:532)
... 1 more


On connecting back the network cable.., connection , channel, exchange, que and binding cant be recovered? Not getting where I am going wrong..




_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Autorecovery Issue

Michael Klishin-2
On 4 June 2014 at 15:22:30, Ranjitha Shet ([hidden email]) wrote:
> > Caught an exception during connection recovery!
> java.net.NoRouteToHostException: No route to host: connect  

This means that RabbitMQ Java client cannot connect to the broker because
OS cannot route packets to it (expected with the network cable being pulled out).

There is a bug fix in the upcoming 3.3.2 release that makes sure any exception
(including the one above) results in a reconnection attempt after a grace period.
Previously only some network I/O exceptions triggered reconnection.

Try with a nighly build of the client if you can. 
--  
MK  

Software Engineer, Pivotal/RabbitMQ
_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Autorecovery Issue

Michael Klishin-2
On 4 June 2014 at 16:19:05, Ranjitha Shet ([hidden email]) wrote:
> > >>>> Try with a nighly build of the client if you can.
>  
> there are other packages released after 3.3.1? Intermediate  
> version?

Please keep rabbitmq-discuss in CC.

http://www.rabbitmq.com/nightlies/rabbitmq-java-client/ has nightly builds
of the Java client. Unfortunately, it seems  there's a problem with producing nightly builds
and the May 5th version does not include the fix I've mentioned.

Here's how to build the client from source:

http://www.rabbitmq.com/build-java-client.html
--  
MK  

Software Engineer, Pivotal/RabbitMQ
_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Autorecovery Issue

Michael Klishin-2
On 4 June 2014 at 16:27:26, Michael Klishin ([hidden email]) wrote:

> > http://www.rabbitmq.com/nightlies/rabbitmq-java-client/ 
> has nightly builds
> of the Java client. Unfortunately, it seems there's a problem  
> with producing nightly builds
> and the May 5th 
> version does not include the fix I've mentioned.
>  
> Here's how to build the client from source:
>  
> http://www.rabbitmq.com/build-java-client.html

Nightly builds are available again:

http://www.rabbitmq.com/nightlies/rabbitmq-java-client/v3.3.1.50605/
--  
MK  

Software Engineer, Pivotal/RabbitMQ
_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Autorecovery Issue

Ranjitha Shet
Hi,

>>>>>> There is a bug fix in the upcoming 3.3.2 release that makes sure any exception
> (including the one above) results in a reconnection attempt after a grace period.
> Previously only some network I/O exceptions triggered reconnection.

I get the same error while using rabbitmq-client.jar with the latest version 3.3.2. 
The server side the RabbitMQ version used is old one ie, 2.8.1

Is it because of the older version used in server side?





_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Autorecovery Issue

Michael Klishin-2


On 10 June 2014 at 09:41:44, Ranjitha Shet ([hidden email]) wrote:
> > Is it because of the older version used in server side?

Recovery is a client library feature.
--
MK

Software Engineer, Pivotal/RabbitMQ
_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Autorecovery Issue

Ranjitha Shet
Hi,

>> Recovery is a client library feature.

Is it fixed in the version 3.3.2.  ?





On Tue, Jun 10, 2014 at 1:14 PM, Michael Klishin <[hidden email]> wrote:


On 10 June 2014 at 09:41:44, Ranjitha Shet ([hidden email]) wrote:
> > Is it because of the older version used in server side?

Recovery is a client library feature.
--
MK

Software Engineer, Pivotal/RabbitMQ


_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Autorecovery Issue

Michael Klishin-2
On 10 June 2014 at 12:04:20, Ranjitha Shet ([hidden email]) wrote:
> > Is it fixed in the version 3.3.2. ?

In 3.3.2, this exception should not prevent further reconnection attempts.

You will still see it logged by default ExceptionHandler, because it is
still being raised until network connectivity is restored.
--
MK

Software Engineer, Pivotal/RabbitMQ
_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Autorecovery Issue

Ranjitha Shet
Hi,
 

>> when I disconnect the network cable, say it gets disconnected when both receiving and publishing takes place.. (Message published and received are different messages(same exchange))  ----> say the name is exchange1 published from server side

Connections, channels, exchange, queue, binding all can be viewed  in Management plugin after reconnecting the network cable. From this can i assume that reconnection is successful?
But if from server side there is a publish to same exchange (exchange1)  after reconnecting (say the server publish some message after 5mins of reconnection) , then i still get this error.
 
DefaultExceptionHandler: Consumer com.rabbitmq.client.QueueingConsumer@5edcf5 (amq.ctag-AcMX2m0FBSPePzrjNqDi7Z) method handleDelivery for channel AMQChannel(amqp://guest@localhost:5672/,1) threw an exception for channel AMQChannel(amqp://guest@localhost:5672/,1):
com.rabbitmq.client.ShutdownSignalException: connection error
at com.rabbitmq.client.QueueingConsumer.checkShutdown(QueueingConsumer.java:172)
at com.rabbitmq.client.QueueingConsumer.handleDelivery(QueueingConsumer.java:124)
at com.rabbitmq.client.impl.ConsumerDispatcher$5.run(ConsumerDispatcher.java:140)
at com.rabbitmq.client.impl.ConsumerWorkService$WorkPoolRunnable.run(ConsumerWorkService.java:85)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.net.SocketException: Software caused connection abort: recv failed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read(BufferedInputStream.java:237)
at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:271)
at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:95)
at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:139)
at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:532)
... 1 more


I am not getting how to solve this..
When checked in Management plugin, after getting this exception, Channel and Queue is no more available.

to receive message what I do is --> 

while(true){

try{

QueueingConsumer.Delivery delivery = consumer.nextDelivery();
..
..
}
catch (ShutdownSignalException sse) {

// notify client about network disconnection
// check if connection and channel is open... if its open then this current thread is delayed for some time so that exchange, queue, binding and consumer are restored..

} catch (java.io.IOException ioe) {

}


} // end of while
 
 
 
 
 


_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Autorecovery Issue

Michael Klishin-2


On 20 June 2014 at 10:16:14, Ranjitha Shet ([hidden email]) wrote:

> > to receive message what I do is -->
>  
> while(true){
>  
> try{
>  
> QueueingConsumer.Delivery delivery = consumer.nextDelivery();  
> ..
> ..
> }
> catch (ShutdownSignalException sse) {
>  
> // notify client about network disconnection
> // check if connection and channel is open... if its open then  
> this current thread is delayed for some time so that exchange,  
> queue, binding and consumer are restored..
>  
> } catch (java.io.IOException ioe) {
>  
> }
>  
>  
> } // end of while

QueueingConsumers currently cannot be recovered: on shutdown,
they modify their internal state in a way that marks them as "done".
Think of them as Iterators which have a logical end.

You have two options:

 * Use a "regular" consumer (recommended)
 * Add a recovery listener and re-create the queueing consumer

Automatic connection recovery simply re-adds the consumer(s) you previously
had, without knowing anything about their implementation and if they can "self terminate"
like the QueueingConsumer does. 
--  
MK  

Software Engineer, Pivotal/RabbitMQ
_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Autorecovery Issue

Ranjitha Shet
Hi,

 * Use a "regular" consumer (recommended)
 * Add a recovery listener and re-create the queueing consumer


I din get what u meant by "regular" consumer.. Should use DefaultConsumer?




On Fri, Jun 20, 2014 at 11:53 AM, Michael Klishin <[hidden email]> wrote:


On 20 June 2014 at 10:16:14, Ranjitha Shet ([hidden email]) wrote:
> > to receive message what I do is -->
>
> while(true){
>
> try{
>
> QueueingConsumer.Delivery delivery = consumer.nextDelivery();
> ..
> ..
> }
> catch (ShutdownSignalException sse) {
>
> // notify client about network disconnection
> // check if connection and channel is open... if its open then
> this current thread is delayed for some time so that exchange,
> queue, binding and consumer are restored..
>
> } catch (java.io.IOException ioe) {
>
> }
>
>
> } // end of while

QueueingConsumers currently cannot be recovered: on shutdown,
they modify their internal state in a way that marks them as "done".
Think of them as Iterators which have a logical end.

You have two options:

 * Use a "regular" consumer (recommended)
 * Add a recovery listener and re-create the queueing consumer

Automatic connection recovery simply re-adds the consumer(s) you previously
had, without knowing anything about their implementation and if they can "self terminate"
like the QueueingConsumer does. 
--
MK

Software Engineer, Pivotal/RabbitMQ


_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Autorecovery Issue

Matthias Radestock-3
On 20/06/14 12:28, Ranjitha Shet wrote:
> I din get what u meant by "regular" consumer.. Should use DefaultConsumer?

Yes, as per http://www.rabbitmq.com/api-guide.html#consuming

Matthias.
_______________________________________________
rabbitmq-discuss mailing list has moved to https://groups.google.com/forum/#!forum/rabbitmq-users,
please subscribe to the new list!

[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss