You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by nlif <na...@dbnet.co.il> on 2007/01/06 22:32:10 UTC

Re: How to Pause/Resume a MessageListener?

Since there have been no replies, let me try to elaborate a little about our
issue:

We run in a cluster, and all nodes use Jencks to pull messages from the AMQ
broker. For various reasons, we may need to "disable" specific nodes from
time to time, and then "enable" them later. While a node is disabled, we
don't want it to pull messages from the broker. However, a disabled node is
not a crashed node: it may very well be up and running; just NOT pulling
messages. Therefore, what we need is a way to "pause" the Jencks connectors,
so that they don't pull messages (and, of course, to "resume" them later,
when the node wishes to process messages again).

Does anybody have any ideas on how to implement this? Is there such a
built-in feature in ActiveMQ or Jencks? We'd hate to develop a mechanism
just to find out later, that there is a way to it...

Thanks in advance,
Naaman



-- 
View this message in context: http://www.nabble.com/How-to-Pause-Resume-a-MessageListener--tf2902158.html#a8198792
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: How to Pause/Resume a MessageListener?

Posted by nlif <na...@dbnet.co.il>.
James,

This is how I do it:

            Map<String, JCAConnector> connectors =
context.getBeansOfType(JCAConnector.class);

            for (JCAConnector connector : connectors.values())
            {
                connector.afterPropertiesSet();
               // OR - connector.destroy();
            }

Where do you think the pause/resume API should reside? The JCAContainer
class? Anywhere else?

Naaman
-- 
View this message in context: http://www.nabble.com/How-to-Pause-Resume-a-MessageListener--tf2902158.html#a8385285
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: How to Pause/Resume a MessageListener?

Posted by James Strachan <ja...@gmail.com>.
On 1/14/07, nlif <na...@dbnet.co.il> wrote:
>
>
> James,
>
> I'd be happy to.

Great!

>  What's the procedure? Should I post code here, or check-in
> to your SVN repository (is that possible at all?).

Here's details of how to submit patches...

http://incubator.apache.org/activemq/contributing.html

Thanks!

-- 

James
-------
http://radio.weblogs.com/0112098/

Re: How to Pause/Resume a MessageListener?

Posted by nlif <na...@dbnet.co.il>.

James, 

I'd be happy to. What's the procedure? Should I post code here, or check-in
to your SVN repository (is that possible at all?).

Naaman

-- 
View this message in context: http://www.nabble.com/How-to-Pause-Resume-a-MessageListener--tf2902158.html#a8337650
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: How to Pause/Resume a MessageListener?

Posted by James Strachan <ja...@gmail.com>.
On 1/9/07, nlif <na...@dbnet.co.il> wrote:
>
>
> Well, it took some time but I've got it to work. What needs to be done is
> calling destroy() and afterPropertiesSet() respectively for all the
> JCAConnectors in the ApplicationContext. This kills/creates the internal
> worker-thread of the JCA resourceAdapter.
> And there is no need to touch the JCAContainer at all. Just the connectors.
>
> Thanks for the moral support :-)

Great! I wonder if you fancy patching the JCAConnector code to make it
a bit easier for folks to destroy/re-create them?

-- 

James
-------
http://radio.weblogs.com/0112098/

Re: How to Pause/Resume a MessageListener?

Posted by nlif <na...@dbnet.co.il>.

Well, it took some time but I've got it to work. What needs to be done is
calling destroy() and afterPropertiesSet() respectively for all the
JCAConnectors in the ApplicationContext. This kills/creates the internal
worker-thread of the JCA resourceAdapter.
And there is no need to touch the JCAContainer at all. Just the connectors.

Thanks for the moral support :-)
-- 
View this message in context: http://www.nabble.com/How-to-Pause-Resume-a-MessageListener--tf2902158.html#a8248579
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: How to Pause/Resume a MessageListener?

Posted by drvillo <f....@gmail.com>.
Actually I haven't tried resuming it...
but looking at the code it seems it should work.

What actually fails?

Btw, since you are using jencks: do you manage to stop the context cleanly?

Cheers
Francesco


nlif wrote:
> 
> 
> Thanks.
> 
> I tried that, and for some reason it didn't work... (the pause works, but
> it doesn't resume later). 
> Have you actually done that?
> In any case, that sounds a bit of an over-kill. But then again, if it
> works, and it's the only way, I'll do it.
> 
> Naaman
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-Pause-Resume-a-MessageListener--tf2902158.html#a8214682
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: How to Pause/Resume a MessageListener?

Posted by nlif <na...@dbnet.co.il>.

Thanks.

I tried that, and for some reason it didn't work... (the pause works, but it
doesn't resume later). 
Have you actually done that?
In any case, that sounds a bit of an over-kill. But then again, if it works,
and it's the only way, I'll do it.

Naaman

-- 
View this message in context: http://www.nabble.com/How-to-Pause-Resume-a-MessageListener--tf2902158.html#a8214566
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: How to Pause/Resume a MessageListener?

Posted by drvillo <f....@gmail.com>.
How about calling JCAConnector.destroy()/start()?

it stops the whole endpoint, but if you have stateless listeners that
shouldn't make
too much of a difference

cheers
Francesco


nlif wrote:
> 
> 
> Thanks for the reply. However, my problem is with asych consumers - a
> MessageListener doesn't "know" its connection, session etc. It is a
> passive component. I need a way to tell the container (be it Jencks or
> whatever) to stop/resume. I really find it hard to believe there would be
> no API to do that... 
> 

-- 
View this message in context: http://www.nabble.com/How-to-Pause-Resume-a-MessageListener--tf2902158.html#a8214262
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: How to Pause/Resume a MessageListener?

Posted by nlif <na...@dbnet.co.il>.

Thanks for the reply. However, my problem is with asych consumers - a
MessageListener doesn't "know" its connection, session etc. It is a passive
component. I need a way to tell the container (be it Jencks or whatever) to
stop/resume. I really find it hard to believe there would be no API to do
that... 
-- 
View this message in context: http://www.nabble.com/How-to-Pause-Resume-a-MessageListener--tf2902158.html#a8214166
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: How to Pause/Resume a MessageListener?

Posted by Adrian Co <ac...@exist.com>.
I think you can temporarily stop a JMS connection from receiving 
messages by calling Connection.stop(). I don't know about Jencks though.

nlif wrote:
> Since there have been no replies, let me try to elaborate a little about our
> issue:
>
> We run in a cluster, and all nodes use Jencks to pull messages from the AMQ
> broker. For various reasons, we may need to "disable" specific nodes from
> time to time, and then "enable" them later. While a node is disabled, we
> don't want it to pull messages from the broker. However, a disabled node is
> not a crashed node: it may very well be up and running; just NOT pulling
> messages. Therefore, what we need is a way to "pause" the Jencks connectors,
> so that they don't pull messages (and, of course, to "resume" them later,
> when the node wishes to process messages again).
>
> Does anybody have any ideas on how to implement this? Is there such a
> built-in feature in ActiveMQ or Jencks? We'd hate to develop a mechanism
> just to find out later, that there is a way to it...
>
> Thanks in advance,
> Naaman
>
>
>
>   


Re: How to Pause/Resume a MessageListener?

Posted by nlif <na...@dbnet.co.il>.
pause - 

            Map<String, JCAConnector> connectors =
context.getBeansOfType(JCAConnector.class);

            for (JCAConnector connector : connectors.values())
            {
                connector.destroy();
            }

resume - 

            Map<String, JCAConnector> connectors =
context.getBeansOfType(JCAConnector.class);

            for (JCAConnector connector : connectors.values())
            {
                connector.afterPropertiesSet();
            }

Let me know if you have any questions.
-- 
View this message in context: http://www.nabble.com/How-to-Pause-Resume-a-MessageListener--tf2902158.html#a8385238
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: How to Pause/Resume a MessageListener?

Posted by YoungSoul <yo...@inbox.com>.
I had a similar requirement, but decided to use the synchronous receive
(timeout) method and basically check to see if I were paused or resumed.  I
know polling is generally not a good idea.  I also considered a pause
message - but then how would one resume?  

For my requirement it was not important to pause immediately so my timeout
could be pretty high and I would actually only timeout when I had nothing to
do so spending cycles on checking did not seem to get in the way of real
processing.  Everytime I received a message I would just make an additional
check to see if I were paused before I went back to the receive(timeout)
method.

I would be interested in seeing how you did it with the listener.

Thanks




nlif wrote:
> 
> Since there have been no replies, let me try to elaborate a little about
> our issue:
> 
> We run in a cluster, and all nodes use Jencks to pull messages from the
> AMQ broker. For various reasons, we may need to "disable" specific nodes
> from time to time, and then "enable" them later. While a node is disabled,
> we don't want it to pull messages from the broker. However, a disabled
> node is not a crashed node: it may very well be up and running; just NOT
> pulling messages. Therefore, what we need is a way to "pause" the Jencks
> connectors, so that they don't pull messages (and, of course, to "resume"
> them later, when the node wishes to process messages again).
> 
> Does anybody have any ideas on how to implement this? Is there such a
> built-in feature in ActiveMQ or Jencks? We'd hate to develop a mechanism
> just to find out later, that there is a way to it...
> 
> Thanks in advance,
> Naaman
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-Pause-Resume-a-MessageListener--tf2902158.html#a8379791
Sent from the ActiveMQ - User mailing list archive at Nabble.com.