How could I have multiple consumers listening to the same queue? #410
Answered
by
Havret
alejandro-jara
asked this question in
Q&A
-
Could it be parameterized that an instance of a solution generates multiple consumers for the same queue? This in order to parallelize the work |
Beta Was this translation helpful? Give feedback.
Answered by
Havret
Dec 27, 2022
Replies: 1 comment 1 reply
-
Hello @alejandro-jara, If you're using ArtemisNetClient directly, all you need to do is to spin up multiple consumers. If you're using public void ConfigureServices(IServiceCollection services)
{
services.AddActiveMq(name: "my-artemis-cluster", endpoints: new[] { Endpoint.Create(host: "localhost", port: 5672, "artemis", "artemis") })
.AddConsumer(address: "a1", RoutingType.Multicast, queue: "q2", new ConsumerOptions { ConcurrentConsumers = 5 }, async (message, consumer, _, _) =>
{
Console.WriteLine("q2: " + message.GetBody<string>());
await consumer.AcceptAsync(message);
})
.EnableQueueDeclaration()
.EnableAddressDeclaration();
services.AddActiveMqHostedService();
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
alejandro-jara
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello @alejandro-jara,
If you're using ArtemisNetClient directly, all you need to do is to spin up multiple consumers. If you're using
Extensions.DependencyInjection
package, it's even simpler. It's just a matter of settingConcurrentConsumers
property to define the desired level of concurrency: