[rabbitmq-discuss] How to tell Java Client running in a separate thread to stop consuming
dusura
dusura at gmail.com
Wed Oct 26 06:57:54 BST 2011
Hi Steve,
thanks for your reply. What you are saying makes a lot of sense.
I guess if I want this kind of design I will have to abandon Spring
AMQP in favour of using the RabbitMQ Java client libraries directly as
they give me access to channel.basicCancel().
Cheers.
On Oct 26, 3:02 am, Steve Powell <st... at rabbitmq.com> wrote:
> dusura,
>
> As I said, there is no 'safe' general mechanism for stopping
> one Java Thread from another. The Interrupt mechanism in Java is
> simply a convenience for *very simple cases*, or for debugging,
> and cannot be regarded as safe on public interfaces.
>
> In particular:
>
> * changes to the design of a service might involve invoking more
> or fewer other threads (in which case you might be interrupting
> the wrong one);
> * services might be invoked which themselves quietly consume
> interrupts;
> * interrupts which fail to be trapped (due to timing considerations)
> can contaminate the thread for the next time it is run;
> * it is not possible to tell the difference between spurious interrupts
> (part of the Java VM rules for wait(timeout)) and deliberate
> external interrupts.
>
> It is much better to architect a solution. For example, in your case,
> send a message to your client application which causes it to perform
> an orderly shutdown (including, one would expect, cancelling consumers
> and closing connections as we have discussed). The client might
> already have such a message architected, or if not, design one.
>
> In the next release of RabbitMQ the thread upon which consumers
> perform their callbacks need neither be the client thread, nor the
> connection thread, nor a thread dedicated to a particular channel.
>
> In these circumstances, you are much better off calling a standard
> interface like basicCancel().
>
> Steve Powell (a happy bunny)
> ----------some definitions from the SPD----------
> Rigatoni n. A prime-ministerial grin.
> Nigella n. The next bottle-size up from a Nebuchadnezzar.
> Homily adv. Rather like a frenchman.
>
> On 21 Oct 2011, at 01:28, dusura wrote:
>
>
>
>
>
>
>
> >http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/2011-October/015...
>
>
>
> _______________________________________________
> rabbitmq-discuss mailing list
> rabbitmq-disc... at lists.rabbitmq.comhttps://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
More information about the rabbitmq-discuss
mailing list