[rabbitmq-discuss] No IOException from basicPublish when connection is lost

Marek Majkowski majek04 at gmail.com
Fri Sep 30 12:43:54 BST 2011


On Wed, Sep 28, 2011 at 14:59,
<mikael.beauvois at non.schneider-electric.com> wrote:
> I have a problem when I call the basicPublish method defined in the Channel
> interface.
>
> In my client, I create a Connection using the ConnectionFactory
> (com.rabbitmq.client.ConnectionFactory) to the broker running on a remote
> host (connected in the local network). Then I create a Channel from this
> Connection.
> I call the basicPublish method in a loop (waiting 10s between each publish).
> During the test, I unplug the network cable from the client running on the
> local host.

RabbitMQ uses AMQP. AMQP uses TCP.

Tcp is a protocol that tries to do best to detect failures, but it's done
using timeouts.

For example, from an idle tcp connection point of view, it's
completely valid that you will
unplug the network cable, wait for a day, and plug it back again.

If you unplug a network cable when tcp connection is transmitting data,
tcp will retry sending over a period of time and will eventually fail.
But this is going to take some time.

> The basicPublish method doesn't throw any exception (I expected at least
> IOException because the network connection is lost).

If you unplug the network cable - the link is lost. The TCP connection
is not lost until tcp gives up retransmitting.

> All calls to
> basicPublish method in the loop never raise the IOException exception (or
> any other exception). Obviously, the broker never received the messages sent
> after loosing the network connection.
>
> A ShutdownListener has been implemented but the shutdownCompleted method is
> called by the RabbitMQ java client stack around 15 minutes after unplugging
> the network cable.
>
> I also tested the disconnection using the command line in a terminal. The
> results are the same.

What do you mean?

> I am running RabbitMQ broker 2.6.1 with the RabbitMQ java client , Linux
> Ubuntu 11.04 with kernel 2.6.38-11 (x86) and I tested my code with 2 JVM
> (OpenJDK and Java HotSpot 1.6.0 (build 1.6.0_27-b07)).
>
> Please, could you help me?

If you want to force tcp connection to be closed quicker, take a look
at tcp heatbeats and/or AMQP keepalive feature.

Cheers,
    Marek


More information about the rabbitmq-discuss mailing list