ActiveMQ reading from multiple queues or topics -- Instantiate a single receiver or multiple receivers?

Viewed 586

I'm implementing a Message Queuing (MQ) reader for ActiveMQ v5.15.x (for receiving messages from ActiveMQ queues or topics) in ASP.NET Core 3.1.

I have a class representing the reader or receiver:

public class MQReader : IMQReader
{
    public MQReader(IConfiguration _config, ILogger _logger)
    {
        // ...setup code of constructor...
    }
    /*
      other methods here
    */
}

Inside one of the methods of the reader I connect to the destination (= ActiveMQ Queue or Topic) and create and add a listener for that destination.

// ...perform preparations...
consumer = session.CreateConsumer(destination);
consumer.Listener += new Apache.NMS.MessageListener(OnMessage);
connection.Start();

This means that one receiver may represent 1..* listeners.

In Startup.cs of the application I configure the service in ConfigureServices method by adding the MQReader as a singleton:

services.AddSingleton<IMQReader>(new MQReader(configuration, logger));

My questions regarding appropriate design:

If the application listens to multiple queues and topics, should I create multiple separate consumers (i.e. readers) for them, each connecting to one single channel (queue or topic)? This would result in configuring multiple separate singleton instances for the reader in ConfigureServices. Or should I implement a single reader (thus 1 singleton added in ConfigureServices) being able to handle various queues/topics?

What is the recommended approach? What is best practice for this scenario?

0 Answers
Related