[rabbitmq-discuss] Cathing broker shut down in a consumer
Matthias Radestock
matthias at rabbitmq.com
Thu Dec 27 15:54:09 GMT 2012
On 21/12/12 18:55, CJ wrote:
> Does anyone know how I can catch Exception on sending to queues ?
It's not clear what you are asking here, e.g. why doesn't the code you
posted previously...
> In the Sender, I used the following code successfully:
>
> while ( numMsgs < maxMsgs ) {
> try { channel.basicPublish( exchange, queueName,
> (persistEnabled) ?
> MessageProperties.PERSISTENT_TEXT_PLAIN : null,
> message.getBytes()); }
> catch (Exception ex) {
> System.out.println("--- Connection Broken ---");
> }
... work?
Perhaps you are asking how to catch errors arising during publishing,
e.g. attempts to publish to a non-existing exchange. Since publishing is
asynchronous, those errors will not show up as exceptions of the
corresponding basicPublish method invocation. You can get hold of the
errors by registering a ShutdownListener on the connection and channel
objects with
http://www.rabbitmq.com/javadoc/com/rabbitmq/client/ShutdownNotifier.html#addShutdownListener%28com.rabbitmq.client.ShutdownListener%29.
Regards,
Matthias.
More information about the rabbitmq-discuss
mailing list