From 6a81e2d2d8aa8fdd5d4f0d26b495723f3e4688d8 Mon Sep 17 00:00:00 2001 From: Chris Patterson Date: Wed, 8 May 2024 10:28:05 -0500 Subject: [PATCH] Added endpoint strategies to the documentation --- .../2.configuration/0.index.md | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/doc/content/3.documentation/2.configuration/0.index.md b/doc/content/3.documentation/2.configuration/0.index.md index f56f24a4a4e..5f6051f6899 100755 --- a/doc/content/3.documentation/2.configuration/0.index.md +++ b/doc/content/3.documentation/2.configuration/0.index.md @@ -173,6 +173,47 @@ x.AddConfigureEndpointsCallback((name, cfg) => }); ``` +## Endpoint Strategies + +Deciding how to configure receive endpoints in your application can be easy or hard, depending upon how much energy you want to spend being concerned with things that usually don't matter. However, there are nuances to the following approaches that should be considered. + +### One Consumer for Each Queue + +Creates a queue for each registered consumer, saga, and routing slip activity. Separate queues are created for execute and compensate if compensation is supported by the activity. + +::alert{type="info"} +This is the preferred approach since it ensures that every consumer can be configured independently, including retries, delivery, and the outbox. It also ensures that messages for a consumer are not stuck behind other messages for other consumers sharing the same queue. +:: + +### Multiple Consumers on a Single Queue + +Configuring multiple consumers, while fully supported by MassTransit, may make sense in certain circumstances, however, proceed with caution as there are limitations to this approach. + +The recommendation here is to configure multiple consumers on a single queue only when those consumers are closely related in terms of business function and each consumer consumes distinct message types. An example might be consumers that each create, update, or delete an entity when the dependencies of those operations are different – create and update may depend upon a validation component, while delete may not share that dependency. + +#### Consume Multiple Message Types + +In situations where it is preferable to consume multiple message types from a single queue, create a consumer that consumes multiple message types by adding more IConsumer interface implementations to the consumer class. + +```csharp +public class AddressConsumer : + IConsumer, + IConsumer +{ +} +``` + +Sagas follow this approach, creating a single queue for each saga and configuring the broker to route message types consumed by the saga that are published to topic/exchanges to the saga’s queue. + +### All Consumers on a Single Queue + +This is never a good idea and is highly discouraged. While it is supported by MassTransit, it’s unlikely to be operationally sustainable. + +Routing slip activities must not be configured on a single queue as they will not work properly. + + + + ## Endpoint Name Formatters _ConfigureEndpoints_ uses an `IEndpointNameFormatter` to format the queue names for all supported consumer types. The default endpoint name formatter returns _PascalCase_ class names without the namespace. There are several built-in endpoint name formatters included. For the _SubmitOrderConsumer_, the receive endpoint names would be formatted as shown below. Note that class suffixes such as _Consumer_, _Saga_, and _Activity_ are trimmed from the endpoint name by default.