在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);
1条答案
按热度按时间rsl1atfo1#
订阅是针对单个流的。因此,默认情况下,您不能拥有更多流。
我建议看看超级流功能。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