The documentation for MassTransit Event Hub Riders recommends using an IEventHubProducerProvider
(part of the MassTransit.EventHub
nuget package) to send messages to an EventHub. However, most MassTransit documentation suggests that when publishing a message from a message consumer, the developer should use "the closest instance of the publish endpoint" to publish the message. In my application, I want to host the same MassTransitStateMachine
in two different contexts:
- Where it is using an in-memory bus and all messages between it and other producers and consumers are part of the same process.
- Where it is using an Event Hub rider to receive and publish messages.
In my mind, the cleanest implementation of this would defer all configuration of where a published message goes to the Bus Configuration, and not take a dependency on MassTransit.EventHub
in the message consumers at all. This led me to ask the question, "can I publish messages with a ConsumeContext and have the message end up on the EventHub? Or do I have to rely on the IEventHubProducerProvider
(or maybe provide my own in-memory implementation of this that uses the ConsumeContext under the hood?)"
Any guidance on how to do this would be appreciated. It seems like the IEventHubProducerProvider
is at odds with the Producers guidance, but more likely I just don't understand something.