Deliver message to only one consumer from multiple subscribers - activemq

I am looking for a way to achieve this.
say I have 10 nodes subscribed to the same queue. one of them publishes the message. but I want the message to be delivered to only one node among all connected.
Further, that node will decide if it wants more nodes to process the same thing then it will again publish it and get extra help.
Is it even possible with ActiveMQ? if not, what else is suitable for this requirement?
Thanks

This looks like the default behavior of an ActiveMQ queue. Just put the message there and one connected consumer will get it.
Don't confuse it with publish/subscribe, that is, topics. If you connect multiple subscribers to a topic, then all would get the same message.

Related

MassTransit(RabbitMQ) multiple subscribers are not receiving the message from a single queue

Apologies if this question has already been answered before.
After searching a lot, I understood that in MassTransit(RabbitMQ) if a message need to deliver to multiple consumers then we need to use different endpoint names (queues) for each of the services. Lets say, if a news is to broadcast in 1000 subscribers then we need to register (ReceiveEndPoint) all 1000 consumers with the publisher and each subscriber has its own queue.
I am not satisfied with this approach and I believe I am mistaken. If the same message need to be delivered then why not all the subscribers get a copy of the message from the same queue?
Is it the limitation of the RabbitMQ or there is a way to do it?

Find the exchange name through which message has been consumed

I have a code which has both consumer and producer. I want to differentiate or find the exact exchange name through which the consumer has consumed the message. For example, I have almost 5 exchanges and I want to know through which exchange out of that 5 the consumer has received it's message. How can this be achieved?
I have done lot of homework but couldn't find a solution.
Messages are consumed from queues, not exchanges.
The way to figure out original exchange that message was published to is to use Firehose Tracer plugin (maybe even with rabbitmq-tracing
plugin alongside).
Alternatively, you may figure out original exchange by comparing queues bindings with message routing key. This usually work well in most cases, unless you have really wired publishers and routing logic.
P.S.: finally, if you have at least read access to publishers code you can figure out where each messages goes from.

activemq round robin between queues or topics

I'm trying to achieve load balancing between different types of messages. I would not know in advance what the messages coming in might be until they hit the queue. I know I can try resequencing the messages, but I was thinking that maybe if there was a way to have the various consumers round robin between either queues or between topics, this would solve my problem.
The main problem i'm trying to solve is that I have many services sending messages to one queue with many consumers feeding off one queue. I do not want one type of service monopolizing the entire worker cluster. Again I don't know in advance what the messages that are going to hit the queue are going to be.
To try to clearly repeat my question:
Is there a way to tell the consumers to round robin between either existing queues or topics?
Thank you in advance.
I found the answer to my question on another post just had to know to look there. I resolved my problem by not creating AMQ consumer but a JMS listener with a composite destination as specified in this post: jms-listener-dynamically-choose-destinations. It turns out the JMS listener automatically round robins though all the queues you assign to it.
Consumers on a Queue will already do round robin processing of the messages on the Queue. The one thing to keep in mind is consumer prefetch which can allow one consumer to grab many messages before others arrive on the Queue so you may need to adjust prefetch depending on your scenario.
Read up on the differences between Queue and Topic here.

How to limit multi-Publisher can not listening the SAME Queue with the NServiceBus?

guys:
I want to use NServiceBus to manage messages.I have more than 5 different Publishers,every publisher is listening different queue.and every publisher have more than 3 different Subscribers.
Currently,the publishers and their Subscribers works well.but unfortunately,i found some messages in which should be processed by one Publisher being received by other program which only know the queue's name.and the original Publisher didn't know that.
So i want to know if there is any solution to prevent other program or Publisher receive myself messages?
If you want to be specific about who subscribes to what, then you need to manually configure the endpoint to subscribe to specific messages(Bus.Subscribe()/Bus.Unsubscribe()). If you don't want a particular endpoint to receive certain messages even though they may show up then you can also load the specific handlers. This can be done by separating the messages/handlers into separate assemblies and then loading the ones you want with Configure.With(assemblyList).

ActiveMQ: Simple topic based cluster

Well, lets say I'm building ActiveMQ based chat application. It's pretty simple. Having only one QUEUE.IN and one TOPIC.OUT. All messages are simply routed right away from QUEUE.IN to TOPIC.OUT. Clients are producing their chat messages to QUEUE.IN and consuming from TOPIC.OUT. That's all.
Now, I wanna cluster it. Don't need something complex. Just run few other identical nodes (A..N). Basically, client, subscribed to A node, sends message to A.QUEUE.IN. This message must then appear on all other nodes (A..N).TOPIC.OUT. This could be easily done by simple camel route that re-route all messages comes to TOPIC.OUT to other nodes, but is there some nice ActiveMQ-native way to do so? Like some queue/topic shared among several AMQ instances?
I think you can find your answer here:
http://activemq.apache.org/how-do-distributed-queues-work.html
You can forward messages to multiple endpoints in activemq using virtual destinations.
http://activemq.apache.org/virtual-destinations.html