iratemike
iratemike

Reputation: 37

Limiting consumer concurrency in MassTransit by message property

I'm aware it's possible to limit concurrency for a given consumer/message type on an endpoint, but I'm wondering if it's possible to limit concurrency across multiple endpoints based on a property of the message. It looks like it might be possible to accomplish something similar using message partitioning, but it seems like that limits a maximum of one message being processed with a given property.

Upvotes: 0

Views: 1697

Answers (1)

Chris Patterson
Chris Patterson

Reputation: 33278

Within a single process, you could create a partitioner and use that partitioner across multiple receive endpoints using the same message type/property, to limit the concurrency up to the partition count with only one message for a given property value at a time.

endpoint.UsePartitioner(...) (there are several overloads) is the filter configuration method – some of which take the partitioner itself as an argument. A partitioner can be created using CreatePartitioner.

There are some sophisticated examples that share the partitioner using a shared dependency, etc. but that level of complexity isn't required.

Also, note that this does not limit concurrency across multiple service instances consuming from the same (or different) queues as partitions are not shared across processes.

Upvotes: 1

Related Questions