0

Is it possible to subscribe to receive messages from multiple streams with a single consumer in RabbitMQ?

I have the following code to subscribe to a single stream and this works correctly. Is it possible to have similar code to subscribe to multiple streams with single consumer, or are multiple consumer required?

using RabbitMQ.Stream.Client;
using RabbitMQ.Stream.Client.Reliable; 

var streamSystem = await StreamSystem.Create(
    new StreamSystemConfig()
    {
        UserName = "guest",
        Password = "guest",
        Endpoints = new List<EndPoint>
        {
            new IPEndPoint(IPAddress.Parse("127.0.0.1"), 5552)
        }
    }
).ConfigureAwait(false);

var confirmationTaskCompletionSource = new TaskCompletionSource<int>();
var consumer = await Consumer.Create( // (1)
    new ConsumerConfig( // (2)
        streamSystem,
        "my-stream")
    {
        OffsetSpec = new OffsetTypeFirst(), // (3)
        MessageHandler = async (stream, consumer, context, message) => // (4)
        {
            Console.WriteLine($"Received message.");
            await Task.CompletedTask.ConfigureAwait(false);
        }
    }
).ConfigureAwait(false);
  • A TCP listener (server) can accept multiple connection where each connection is from a different IP address. The socket (connection) is "ar" in the accept method. So every new connection is a new socket and you have response to the same socket the message was received. The socket has a remote endpoint which is the IP of the client. See : https://learn.microsoft.com/en-us/dotnet/api/system.net.sockets.tcplistener.beginaccepttcpclient?force_isolation=true&view=net-7.0 – jdweng Apr 04 '23 at 14:09
  • 1
    Would this help? See: https://stackoverflow.com/questions/49926666/rabbitmq-single-consumer-with-multiple-queue – SoftwareDveloper Apr 04 '23 at 19:37

1 Answers1

0

The subscription is for a single stream. So, by default, you can't have more streams.

I'd suggest having a look at the super-stream feature. https://rabbitmq.github.io/rabbitmq-stream-dotnet-client/stable/htmlsingle/index.html#super-streams

Here is an example of how to use it: https://github.com/rabbitmq/rabbitmq-stream-dotnet-client/tree/main/docs/SuperStream

phuzi
  • 12,078
  • 3
  • 26
  • 50
Gabriele Santomaggio
  • 21,656
  • 4
  • 52
  • 52