Hi,
I'm using the rabbit java client and rabbitmq server for some simple
messaging and I can't seem to get the shutdown listener to work as expected.

Basically, I'm attaching a shutdownlistener to the connection and then start
sending messages every second. If I shutdown the server I would expect the
shutdownlistener to be invoked at some point on the client but this never
occurs. I only get an AlreadyClosedException when calling basicPublish on
the channel.

Test case:

package foobar;

import com.rabbitmq.client.*;

import java.io.IOException;


public class TestRabbitShutdownListener implements ShutdownListener,
Runnable
{
private Connection connection;
private Channel channel;
private String exchange;
private int ticket;

public static void main(String[] args) throws IOException,
InterruptedException
{
ConnectionParameters cp = new ConnectionParameters();
cp.setUsername("guest");
cp.setPassword("guest");

ConnectionFactory cf = new ConnectionFactory(cp);

TestRabbitShutdownListener trsl = new TestRabbitShutdownListener(
cf,
"foobar"
);

Thread t = new Thread(trsl);
t.start();
t.join();
Thread.sleep(5000);

}

public TestRabbitShutdownListener(ConnectionFactory connectionFactory,
String exchange) throws IOException
{
this.exchange = exchange;
this.connection = connectionFactory.newConnection("localhost");
this.connection.addShutdownListener(this);

setupChannel();
}

private void setupChannel() throws IOException
{
this.channel = connection.createChannel();
this.ticket = channel.accessRequest("/data");

channel.exchangeDeclare(
ticket,
exchange,
"fanout"
);
}

public void run()
{
while (true)
{
try
{
System.out.println("Sending msg..");

channel.basicPublish(ticket, exchange, "",
MessageProperties.BASIC, new byte[]{});
Thread.sleep(1000);
}
catch (IOException e)
{
e.printStackTrace();
return;
}
catch (InterruptedException e)
{
System.out.println("thread interrupted");
return;
}
}
}

public void shutdownCompleted(ShutdownSignalException e)
{
System.out.println("shutdownCompleted: " + e.getMessage());
e.printStackTrace();
}
}


--
.henric.larsson.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20081104/bd128294/attachment.htm

Search Discussions

  • Ben Hood at Nov 4, 2008 at 12:13 am
    Henric,

    On Mon, Nov 3, 2008 at 11:58 PM, Henric Larsson
    wrote:
    I'm using the rabbit java client and rabbitmq server for some simple
    messaging and I can't seem to get the shutdown listener to work as expected.
    Basically, I'm attaching a shutdownlistener to the connection and then start
    sending messages every second. If I shutdown the server I would expect the
    shutdownlistener to be invoked at some point on the client but this never
    occurs. I only get an AlreadyClosedException when calling basicPublish on
    the channel.
    I've just run your testcase against the latest default branch in our
    tree and the shutdownCompleted() method appears to get called.

    Although I am not aware of the specifics, I know that Hubert has down
    a lot of work on shutdown negotiation in the Java client subsequent to
    the 1.4.0 release, so he *may* have encountered this scenario, but
    I'll let him comment on that.

    So your short term solution would be to get a copy of the latest
    source and try that.

    HTH,

    Ben
  • Ben Hood at Nov 4, 2008 at 12:57 am
    Henric,
    On Tue, Nov 4, 2008 at 12:13 AM, Ben Hood wrote:
    Although I am not aware of the specifics, I know that Hubert has down
    a lot of work on shutdown negotiation in the Java client subsequent to
    the 1.4.0 release, so he *may* have encountered this scenario, but
    I'll let him comment on that.
    I've just run this against this against the 1.4.0 release, and it
    works as well. There is a slight difference in the way that the
    shutdown event is propagated in 1.4.0 compared to the current version,
    but in both cases, the handler does get called.

    Can you package up a tarball and send it so that we can reproduce the issue?

    Ben

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprabbitmq-discuss @
categoriesrabbitmq
postedNov 3, '08 at 11:58p
activeNov 4, '08 at 12:57a
posts3
users2
websiterabbitmq.com
irc#rabbitmq

2 users in discussion

Ben Hood: 2 posts Henric Larsson: 1 post

People

Translate

site design / logo © 2023 Grokbase