What is the difference between a Handler and a Consumer in MassTransit? I've seen examples that use one or the other, but conceptually, I'm unclear on what the difference is between the two and why you would want to choose one or the other.
By default, MassTransit uses JSON to serialize messages, while simultaneously suppporting the deserialization of JSON, BSON, and XML messages. Additional deserializers can be added, and the serializer can be changed for each receive endpoint or the entire bus.
MassTransit is a lightweight service bus for building distributed . NET applications. The main goal is to provide a consistent, . NET friendly abstraction over the message transport.
A Consumer is a type you register that has a specialized handler which handles the lifecycle of your Consumer object.
A handler is effectively just a generic event handler.
You would use a handler if just need a small Action<>
block to resolve whatever action on your message. You would use a Consumer if you want to register a type, that has a lifecycle, to resolve whatever action on your message. Generally, you'll end up wanting a Consumer because want your container to resolve dependencies for the type instead of just having them in scope of your handler. But handlers work great for small things or request-response scenarios.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With