A consumer is a class that accepts delivery of messages for which it has subscribed.
When a message that is consumed by the consumer is received, the service bus obtains an instance of the class from the container and dispatches the message to the consumer. Therefore, it is expected that the class is registered in the container (as a transient since like a webpage basic consumers should have no state). To register a class to consume messages (subscribing), a call to bus.Subscribe<T>(); is made, where T is the name of the class to register.
For example, a class that consumes all messages of type SomeMessage would be defined with the syntax shown:
public class SomeConsumer :
Consumes<SomeMessage>.All
{
public void Consume(SomeMessage message)
{
// do something with the message
}
}
Above Consumes<T>.All is an interface that expects the Consume(T message) method to be implemented. There are variations of this interface that define additional message acceptance criteria, including Consumes<T>.Selected (for selective consumer) and Consumes<T>.For<K> (for correlated consumer).
The are various consumer types that are supported by MassTransit.
Comments (0)
You don't have permission to comment on this page.