Process multiple ActiveMQ messages in multiple consumers

1

When I send 3 messages to an ActiveMQ queue, if I have two consumers, two messages are automatically assigned to one consumer and one to another consumer ... then if I want to get the 3 messages from a consumer, I can not.

Is there any way to get the messages sent to a queue, from one consumer or another interchangeably, without there being any type of pre-assignment?

Thank you.

    
asked by Sem 24.10.2016 в 18:39
source

1 answer

0

Let's start from the base that queus do not have any type of pre-assignment

Introduction to Apache ActiveMQ

You'll see what he says

  

Our consumer will process all the messages that are in the queue "on demand" (when it is executed). If we wanted to process each message when it reaches the queue (this is not our case) we should implement the javax.jms.MessageListener interface and launch our process as a thread that is waiting (Thread).

I understand you are not using java, but the equivalent in c # would be the

Asynchronous

assigning an event in Listener

using(IMessageConsumer consumer = session.CreateConsumer(destination))
using(IMessageProducer producer = session.CreateProducer(destination))
{
    // Start the connection so that messages will be processed.
    connection.Start();
    producer.Persistent = true;
    producer.RequestTimeout = receiveTimeout;
    consumer.Listener += new MessageListener(OnMessage);

    //resto codigo

The issue is that in your case you will have two consumers with which you require a load balancing that allows you to distribute the messages

Maybe you should evaluate Clustering

    
answered by 24.10.2016 в 19:00