Why is pausing a queue not a broker function?

2019-07-23 02:57发布

问题:

I was looking for an ActiveMQ broker admin command, to tell it to pause a queue - that is:

  • continue accepting messages from producing clients
  • cease delivering to consuming clients, allowing the queue backlog to grow until the queue is resumed, whereupon the backlog is sent to clients.

I was unable to find such a command. The commonest answer was that it should be managed at the client end -- that is, locate every consumer and stop it. Other answers were workarounds, like manipulating network routes or firewalls so that the clients and broker could no longer communicate.

A cursory survey of other message queues indicates that ActiveMQ is not unusual in this regard.

It seems to me there are two reasons this functionality might not be implemented:

  • It is difficult to implement -- but I can't think of any reason why.
  • It is counter to the design philosophy of message queues

Which is it, and why?

回答1:

Probably not too complicated to implement - as you say. I don't know if it's an active design decision of if there has been no demand. Other similar products such as IBM WebSphere MQ implements "get/put inhibited" on queues, so it's obviously is not totally against the philosofy of messaging - rather a tool to operate and trouble shoot live systems.

I'm a bit biased, but I actually like to decouple the sender from the receive (if the are two different systems, that might eventually get switched/upgraded/changed..).

An easy way to decouple the systems, and be able to do what you want is to make the sender send to one queue "DATA.OUT" and the receiver listen to another "DATA.IN". Then you can use Apache Camel (which is typically bundled with ActiveMQ to achieve Enterprise Integration Patterns), to route from DATA.OUT to DATA.IN.

A Camel Route is possible to start/stop via JMX, which will achieve something similar to what you described.

I guess ActiveMQ design in the matter rather have you do these kind of things in a middleware layer, such as Apache Camel, rather than direct on the queues.



回答2:

Being able to pause a queue is supported in the newly released ActiveMQ 5.12.0:

When the queue is "paused":

  • NO messages sent to the associate consumers

  • messages still to be enqueued on the queue

  • ability to be able to browse the queue

  • all the JMX counters for the queue to be available and correct.

...

implemented pause/resume/isPaused queue view mbean ops and attribute

when paused, there is no dispatch to regular queue consumers, send and browse work as normal. Any inflight messages will continue inflight till ackes as normal.

See https://issues.apache.org/jira/browse/AMQ-5229

If you have Jolokia enabled (I think it is enabled by default nowadays), you can use something like the following curl request to pause the queue:

curl --user admin:admin http://127.0.0.1:8161/api/jolokia/exec/org.apache.activemq:brokerName=localhost,destinationName=myQueue,destinationType=Queue,type=Broker/pause

(Using the default username, password and broker name and a queue called myQueue)

Replace "pause" with "resume" in order to resume the queue.



标签: activemq