Check the availability of a specific queue in ActiveMQ? - activemq

Is there any way I can check the whether a specific queue already exists or not in ActiveMQ?

http://activemq.apache.org/how-can-i-get-a-list-of-the-topics-and-queues-in-a-broker.html

You will have to be a bit more specific if you want a concrete example: do you want to do it with a Web Console, JMX or programmatically. ActiveMQ btw creates queues on demand, whenever you need one, not like WebSphere MQ where you will get an exception if the queue does not exist.

Related

RabbitMQ Pika - how to check if a consumer is active

Does anyone know what is the easiest way to check if a consumer is active for a particular queue? I could hit the api on localhost manually, but I'd love a way to do this with Pika.
For example, I have a queue xyz I want to know how many consumers are listening to that queue.
You can do a queue.declare with passive=true for the same queue you want to get the consumer count from. This will return a response (queue.declare-ok) which includes the consumer count.
From the protocol reference documentation:
bit passive
If set, the server will reply with Declare-Ok if the queue already
exists with the same name, and raise an error if not. The client can
use this to check whether a queue exists without modifying the server
state.

Is it good practice to create AMQP queues manually or programmatically?

I'm in the process of implementing various remote methods/RPCs on the top of AMQP (RabbitMQ in particular). When a worker (or a client) comes online, it could, in theory, declare (create) a queue on the exchange. The other approach is to just start using a queue and assume that it already exists on the exchange.
Which approach is more common? Creating queues manually has a higher administrative cost, maybe; however, it can result in a more consistent environment if we decouple queue management from queue usage.
It depends what is the requirement. If you have a fixed number of queues and dont need it to be generated dynamically, then go for manual. Example : It is a integration application and I know I have 3 consumers A,B,C then I will manually create 3 queues. Another example in a chat application for every logged in user I want to create a queue, in that case queues should be created programatically. And in case manual creation, you have more control to implement permissions and ACLs.
Meanwhile I found out that according to RabbitMQ applications should take care of managing the queues they use.

View delayed messages in ActiveMQ?

Is there any way to keep track of delayed (scheduled) messages in ActiveMQ?
I don't see anything in the AMQ web console, they seem to get to the queue only when the delay expires... Also I couldn't find it in JMX console, maybe I didn't search well enough?
I wrote an article on this awhile back.
The gist of it is that you can use a standard JMS message consumer to retrieve all or some of the scheduled messages and manage them using a standard producer. The scheduled messages are kept in a separate store and only injected into the broker once their scheduled time arrives so they won't show up in the web console.
here might you want ,only click the 'Scheduled ' you can find this

Why is pausing a queue not a broker function?

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?
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.
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.

KahaDBPersistenceAdapter and createQueueMessageStore

I am not sure if I need to call createQueueMessageStore for each queue that will be persisted, and it not, what is the purpose of this call ? Is setting the adapter on the broker enough without individual queueMessageStores ?
createQueueMessageStore() is used by the ActiveMQ Broker - you don't need to call this.
ActiveMQ automatically creates Queues and Topics on demand -
so if you send a message to a Queue foo.bar the ActiveMQ broker will check to see if it exists, and if it doesn't it will create it for you (using the createQueueMessageStore() call).