Skip to content

[Host.RabbitMq] Multiple consumers with varying concurrency #205

Closed

Description

@robert94p

how to process messages in parallel when using RabbitMq?

Activity

  1. self-assigned this
    on Jan 9, 2024
  2. zarusz commented on Jan 9, 2024

    @zarusz
    Owner

    hello @robert94p ,

    By default, the underlying RabbitMq net driver uses a concurrency of 1.
    Following this it can be adjusted on the ConnectionFactory object.

    For example, try to set this via SMB like so:

    services.AddSlimMessageBus((mbb) =>
    {
        mbb.WithProviderRabbitMQ(cfg =>
        {
            cfg.ConnectionFactory.ConsumerDispatchConcurrency = 2; // default is 1
            // ...
        }
    }

    Please let me know if this worked for you.

  3. robert94p commented on Jan 11, 2024

    @robert94p
    Author

    registered several buses for one consumer. While it works

  4. zarusz commented on Jan 11, 2024

    @zarusz
    Owner

    Did you try the provided suggestion (with ConsumerDispatchConcurrency setting)?
    Sounds like you've taken another route, can you explain what you mean several buses for one consumer?
    Thanks

  5. zarusz commented on Jan 14, 2024

    @zarusz
    Owner

    As part of #207 I have updated the docs to include information on how to increase concurrency.

    If you run into any problems, please re-open the issue and let me know.

    Thanks!

  6. zarusz commented on Dec 19, 2024

    @zarusz
    Owner

    Moving the following from @robert94p #310 (comment):

    Apologies, I wrote this under the wrong issue; it should have been under https://github.com/zarusz/SlimMessageBus/issues/205
    
    I need 2 or more consumers. I have one producer, one exchange, and three queues for three different consumers. When publishing a message, the target queue is determined via the routingKey.
    
    One of the consumers performs a resource-intensive operation, so it needs to be limited to processing only 2 messages in parallel. The other consumers can handle more messages simultaneously.
    
    I would like to configure the number of messages that can be processed concurrently per consumer, similar to how it works in MemoryMessageBus. Currently, messages are processed based on the ConsumerDispatchConcurrency setting, which applies globally to all consumers.
    
  7. reopened this on Dec 19, 2024
  8. changed the title [-] Concurrently processed messages for RabbitMq transport[/-] [+][Host.RabbitMq] Multiple consumers with varrying concurrency[/+] on Dec 19, 2024
  9. changed the title [-][Host.RabbitMq] Multiple consumers with varrying concurrency[/-] [+][Host.RabbitMq] Multiple consumers with varying concurrency[/+] on Dec 19, 2024
  10. zarusz commented on Dec 19, 2024

    @zarusz
    Owner

    @robert94p I believe this is a good example of what you are trying to achieve, correct?
    https://www.rabbitmq.com/tutorials/tutorial-four-dotnet

    Here is the preview release to try out:
    https://www.nuget.org/packages/SlimMessageBus.Host.RabbitMQ/2.6.2-rc10

    Here is a pseudo sample:

    services.AddSlimMessageBus(mbb => 
    {
      mbb.Produce<PingMessage>(x => x
            .Exchange("exchange", exchangeType: ExchangeType.Direct)
            .RoutingKeyProvider((m, p) => m.Label));
    
      // messages with blue routing key will get 1 concurrency
      mbb.Consume<PingMessage>(x => x
          .Queue("queue", autoDelete: false)
          .ExchangeBinding("orders", routingKey: "blue")
          .Instances(1));
    
      // messages with red routing key will get 10 concurrency
      mbb.Consume<PingMessage>(x => x
          .Queue("queue", autoDelete: false)
          .ExchangeBinding("orders", routingKey: "red") 
          .Instances(10));  
    });

    Let me know if that works for you.

  11. zarusz commented on Dec 23, 2024

    @zarusz
    Owner

    I just pushed a refined version:
    https://www.nuget.org/packages/SlimMessageBus.Host.RabbitMQ/2.6.2-rc12

    With that, the overall concurrency should be improved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions