MassTransit

 

Selective Consumer

Page history last edited by Chris Patterson 1 yr ago

A selective consumer is a class that conditionally accepts delivery of messages for which it has subscribed based on a preview of the message.

 

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 some messages of type SomeMessage would be defined with the syntax shown:

 

public class SomeConsumer :
Consumes<SomeMessage>.For<Guid>
{
public bool Accept(SomeMessage message)
{
return true;
}
public void Consume(SomeMessage message)
{
// do something with the message
}
}

  

Comments (0)

You don't have permission to comment on this page.