是否可以在RabbitMQ中订阅接收来自多个流的消息?
我有以下代码来订阅单个流,这可以正常工作。是否有可能使用类似的代码来订阅具有单个消费者的多个流,或者需要多个消费者?
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);
订阅的是单个流。所以,默认情况下,你不能有更多的流。
我建议你看看超级流功能。https://rabbitmq.github.io/rabbitmq-stream-dotnet-client/stable/htmlsingle/index.html super-streams
下面是如何使用它的一个例子:https://github.com/rabbitmq/rabbitmq-stream-dotnet-client/tree/main/docs/SuperStream