elsa-workflows / elsa-workflows/elsa-core

MassTransit Azure Service Bus Activities in Programmatic Workflows

Open
#5,887 6 comments 0 reactions 0 assignees View on GitHub
triaged
Dominant language
C#
Stars
7.9k
Forks
1.5k
Avg merge
15h 22m
Merged PRs (30d)
114

Description

I´m trying to use [UseMassTransit().UseAzureServiceBus()](https://v3.elsaworkflows.io/docs/integrations/masstransit/introduction#installing-mass-transit) to start my workflow but am totally unable to get it working. The only other thing I found was [this discussion](https://github.com/elsa-workflows/elsa-core/discussions/2878) but that is version 2.

This here is what I currently have **working** in my **normal** MassTransit setup
```csharp
using MassTransit;
public class AssignmentCreatedHandler(
: IConsumer
{
public async Task Consume(ConsumeContext context)
{
// handle code omitted
}
}

public class SubscriptionAssignmentCreated
{
public Subscription Subscription { get; }
public Guid CustomerId { get; }

public SubscriptionAssignmentCreated(Subscription Subscription, Guid CustomerId)
{
this.Subscription = Subscription;
if (!(CustomerId != Guid.Empty))
{
throw new ArgumentException("Customer id must contain a valid value");
}

this.CustomerId = CustomerId;
}
}
```

and then in my Program.cs

```csharp
builder.Services.AddMassTransit(options =>
{
options.AddConsumer();

options.UsingAzureServiceBus((context, cfg) =>
{
cfg.Host(
new Uri($"sb://..."),
bus =>
{
bus.ConnectionString = "Endpoint=sb://....";
}
);
cfg.SubscriptionEndpoint("SubscriptionAssignmentCreated",
configurator => configurator.ConfigureConsumer(context));

cfg.ConfigureEndpoints(context);
});
});
```

But this here is as far as I have been able to get with **Elsa version 3.2.0-rc4.**

```csharp
builder.Services.AddElsa(elsa =>
{
elsa.UseWorkflowManagement(management => management.UseEntityFrameworkCore());
elsa.UseWorkflowRuntime(runtime => runtime.UseEntityFrameworkCore());
elsa.UseIdentity(identity =>
{
identity.TokenOptions = options => options.SigningKey = "sufficiently-large-secret-signing-key";
identity.UseAdminUserProvider();
});
elsa.UseDefaultAuthentication(auth => auth.UseAdminApiKey());
elsa.UseWorkflowsApi();
elsa.UseRealTimeWorkflows();
elsa.UseCSharp();
elsa.UseHttp();
elsa.UseScheduling();

elsa.UseMassTransit(massTransit =>
{
massTransit.AddConsumer("AssignmentCreatedHandler", isTemporary: false);
massTransit.UseAzureServiceBus(
"Endpoint=sb://...",
serviceBusFeature => serviceBusFeature.ConfigureServiceBus = bus =>
{
bus.PrefetchCount = 4;
bus.LockDuration = TimeSpan.FromMinutes(5);
bus.MaxConcurrentCalls = 32;
bus.MaxDeliveryCount = 8;

// I'm guessing I don´t need to setup SubscriptionEndpoint as above to setup a "handler"
// since the AssignmentConsumedWorkflow should be picking up the event.. 🤷‍♂️
}
);
});
elsa.AddActivitiesFrom();
elsa.AddWorkflowsFrom();
});
```

Here is the workflow that should be the starting point when a message hits. I followed [MessageReceivedTriggerWorkflow ](https://github.com/elsa-workflows/elsa-core/blob/84893e6c80f2d7ee6979938a5117f519d64efe98/test/component/Elsa.AzureServiceBus.ComponentTests/Workflows/MessageReceivedTriggerWorkflow.cs)

```csharp
public class AssignmentConsumedWorkflow() : WorkflowBase
{
public static readonly string DefinitionId = Guid.NewGuid().ToString();
public static readonly string Topic = "my_azure_service_bus_topic_name";
public static readonly object Signal1 = new();
public static readonly object Signal2 = new();

protected override void Build(IWorkflowBuilder builder)
{
builder.WithDefinitionId(DefinitionId);
var message = builder.WithVariable();
builder.Root = new Sequence
{
Activities =
{
new MessageReceived(Topic, nameof(SubscriptionAssignmentCreated))
{
CanStartWorkflow = true,
TransportMessage = new(message)
},
new If
{
Condition = new Input(context =>
{
var msg = message.Get(context);
return msg?.Subscription?.Features != null &&
msg.Subscription.Features.Any(f => f.Code == FeatureCodes.SomeCode);
}),
Then = new Sequence
{
Activities =
{
new TheClassThatShouldDoSomethingActivity(),
}
},
Else = new Sequence
{
Activities =
{
new WriteLine("Subscription or Features is null or does not contain the required feature."),
new WriteLine("False!")
}
}

}
}
};
}
}
```

But what ever I try I just can´t get the `AssignmentConsumedWorkflow` to fire.

Hope you can assist me in the right direction before I give up 😅

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.