elsa-workflows / elsa-workflows/elsa-core
[ENH] Support MultiBus in MassTransit Workflow Dispatcher
- Dominant language
- C#
- Stars
- 7.9k
- Forks
- 1.5k
- Avg merge
- 15h 22m
- Merged PRs (30d)
- 114
Description
## Enhancement Request
### Enhancement Overview
Hello, I have an application that is configured to use MassTransit with a Kafka Rider and I would like to use Elsa with the MassTransit Workflow Dispatcher. The problem is that MassTransit throws a MassTransit.ConfigurationException: 'AddMassTransit() was already called and may only be called once per container. To configure additional bus instances, refer to the documentation: https://masstransit-project.com/usage/containers/multibus.html'.
My code is shown below:
```csharp
services.AddElsa(elsa =>
{
elsa.UseWorkflowRuntime(runtime =>
{
runtime.UseMassTransitDispatcher();
});
elsa.UseMassTransit(massTransit =>
{
massTransit.UseRabbitMq(rabbitMQSettings.ConnectionString);
});
});
services.AddMassTransit(config =>
{
config.AddRider(rider =>
{
rider.AddConsumer();
rider.AddConsumer();
rider.UsingKafka((context, c) => { });
});
});
```
### Proposed Enhancement
As described in the exception message, I would expect to be able to configure Elsa to use MassTransit with MultiBus support https://masstransit-project.com/usage/containers/multibus.html.
I expect this to be as simple as creating a new interface inheritting from IBus
```csharp
public interface IElsaBus : IBus { }
```
and use it when registering MassTransit.
```csharp
services.AddMassTransit();
```
As the last step, all references of IBus need to be replaced with the new interface.
### Impact of Enhancement
Any application already using MassTransit, will need its code to be modified in order to support Elsa with the MassTransit Workflow Dispatcher, but sometimes this is not possible.
For example, in my scenario I wish I could just do:
```csharp
services.AddMassTransit(config =>
{
config.AddRider(rider => { });
});
```
but unfortunately Riders in MassTransit don't support the MultiBus configuration, leaving me no option but to not use the MassTransit Workflow Dispatcher.
Contributor guide
Assessment
This issue has not been assessed yet.