Skip to content

Commit

Permalink
Added endpoint strategies to the documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
phatboyg committed May 8, 2024
1 parent 3e8be46 commit 6a81e2d
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions doc/content/3.documentation/2.configuration/0.index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> interface implementations to the consumer class.

```csharp
public class AddressConsumer :
IConsumer<CreateAddress>,
IConsumer<UpdateAddress>
{
}
```

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.
Expand Down

0 comments on commit 6a81e2d

Please sign in to comment.