Add Rebus service bus providers for Azure Service Bus and RabbitMQ

This commit is contained in:
Sipke Schoorstra 2020-11-22 13:05:34 +01:00
parent e6227e887f
commit 3d67c195ac
10 changed files with 118 additions and 2 deletions

View file

@ -142,6 +142,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Activities.Rebus", "sr
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Samples.RebusWorker", "src\samples\Elsa.Samples.RebusWorker\Elsa.Samples.RebusWorker.csproj", "{A855C6B9-1548-4183-926C-75D80CEEF510}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "servicebus", "servicebus", "{47EDFC14-BB99-44BF-A447-035D40D7347B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.ServiceBus.AzureServiceBus", "src\servicebus\Elsa.ServiceBus.AzureServiceBus\Elsa.ServiceBus.AzureServiceBus.csproj", "{D3440E66-A871-4AB0-A1E0-8B3864ACA16A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.ServiceBus.RabbitMq", "src\servicebus\Elsa.ServiceBus.RabbitMq\Elsa.ServiceBus.RabbitMq.csproj", "{FC656D28-1AA3-462D-9B18-A10436E47C08}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -349,6 +355,14 @@ Global
{A855C6B9-1548-4183-926C-75D80CEEF510}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A855C6B9-1548-4183-926C-75D80CEEF510}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A855C6B9-1548-4183-926C-75D80CEEF510}.Release|Any CPU.Build.0 = Release|Any CPU
{D3440E66-A871-4AB0-A1E0-8B3864ACA16A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D3440E66-A871-4AB0-A1E0-8B3864ACA16A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D3440E66-A871-4AB0-A1E0-8B3864ACA16A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D3440E66-A871-4AB0-A1E0-8B3864ACA16A}.Release|Any CPU.Build.0 = Release|Any CPU
{FC656D28-1AA3-462D-9B18-A10436E47C08}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FC656D28-1AA3-462D-9B18-A10436E47C08}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FC656D28-1AA3-462D-9B18-A10436E47C08}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FC656D28-1AA3-462D-9B18-A10436E47C08}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -416,6 +430,9 @@ Global
{922F1EB6-5C8F-45DC-82A8-C651E4554542} = {5E5E1E84-DDBC-40D6-B891-0D563A15A44A}
{115DEB38-679F-467E-8F87-9E669DFD2EB8} = {B43B546E-23F3-46E8-ACB7-D04F05CDA180}
{A855C6B9-1548-4183-926C-75D80CEEF510} = {5E5E1E84-DDBC-40D6-B891-0D563A15A44A}
{47EDFC14-BB99-44BF-A447-035D40D7347B} = {DA71CDAA-8DD3-4D5F-9FBD-8E4B37A2D925}
{D3440E66-A871-4AB0-A1E0-8B3864ACA16A} = {47EDFC14-BB99-44BF-A447-035D40D7347B}
{FC656D28-1AA3-462D-9B18-A10436E47C08} = {47EDFC14-BB99-44BF-A447-035D40D7347B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8B0975FD-7050-48B0-88C5-48C33378E158}

View file

@ -17,6 +17,12 @@ services:
ports:
- "6379:6379"
rabbitmq:
image: "rabbitmq:3-management"
ports:
- "15672:15672"
- "5672:5672"
smtp4dev:
image: rnwood/smtp4dev:linux-amd64-3.1.0-ci0856
ports:

View file

@ -107,7 +107,7 @@ namespace Elsa
return this;
}
public ElsaOptions SetupServiceBus(Action<ServiceBusEndpointConfigurationContext> setup)
public ElsaOptions UseServiceBus(Action<ServiceBusEndpointConfigurationContext> setup)
{
ConfigureServiceBusEndpoint = setup;
return this;

View file

@ -13,5 +13,7 @@
<ItemGroup>
<ProjectReference Include="..\..\activities\Elsa.Activities.Rebus\Elsa.Activities.Rebus.csproj" />
<ProjectReference Include="..\..\core\Elsa\Elsa.csproj" />
<ProjectReference Include="..\..\servicebus\Elsa.ServiceBus.AzureServiceBus\Elsa.ServiceBus.AzureServiceBus.csproj" />
<ProjectReference Include="..\..\servicebus\Elsa.ServiceBus.RabbitMq\Elsa.ServiceBus.RabbitMq.csproj" />
</ItemGroup>
</Project>

View file

@ -1,9 +1,12 @@
using Elsa.Activities.Rebus.Extensions;
using Elsa.Samples.RebusWorker.Messages;
using Elsa.Samples.RebusWorker.Workflows;
using Elsa.ServiceBus.AzureServiceBus;
using Elsa.ServiceBus.RabbitMq.Extensions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using NodaTime;
using Rebus.Logging;
using YesSql.Provider.Sqlite;
namespace Elsa.Samples.RebusWorker
@ -20,7 +23,10 @@ namespace Elsa.Samples.RebusWorker
.ConfigureServices((hostContext, services) =>
{
services
.AddElsa(option => option.UsePersistence(db => db.UseSqLite("Data Source=elsa.db;Cache=Shared")))
.AddElsa(option => option
.UsePersistence(db => db.UseSqLite("Data Source=elsa.db;Cache=Shared"))
.UseAzureServiceBus("Endpoint=sb://elsa-workflows.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=n4NBTw9eSX12AG5BdIkyxCRroJGvh+EMOOM8ypWxWrQ=", LogLevel.Debug))
//.UseRabbitMq("amqp://localhost"))
.AddConsoleActivities()
.AddTimerActivities(options => options.SweepInterval = Duration.FromSeconds(1))
.AddRebusActivities<Greeting>()

View file

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\core\Elsa.Core\Elsa.Core.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Rebus.AzureServiceBus" Version="7.1.6" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=extensions/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View file

@ -0,0 +1,27 @@
using Elsa.Extensions;
using Elsa.Services;
using Microsoft.Azure.ServiceBus.Primitives;
using Rebus.Config;
using Rebus.Logging;
using Rebus.Routing.TypeBased;
namespace Elsa.ServiceBus.AzureServiceBus
{
public static class ElsaOptionsExtensions
{
public static ElsaOptions UseAzureServiceBus(this ElsaOptions elsaOptions, string connectionString, LogLevel logLevel = LogLevel.Info, ITokenProvider tokenProvider = default)
{
return elsaOptions.UseServiceBus(context => ConfigureAzureServiceBusEndpoint(context, connectionString, logLevel, tokenProvider));
}
private static void ConfigureAzureServiceBusEndpoint(ServiceBusEndpointConfigurationContext context, string connectionString, LogLevel logLevel, ITokenProvider tokenProvider)
{
var queueName = context.QueueName;
context.Configurer
.Logging(l => l.ColoredConsole(logLevel))
.Transport(t => t.UseAzureServiceBus(connectionString, queueName, tokenProvider))
.Routing(r => r.TypeBased().Map(context.MessageTypeMap));
}
}
}

View file

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\core\Elsa.Core\Elsa.Core.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Rebus.RabbitMq" Version="7.3.0" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,26 @@
using Elsa.Extensions;
using Elsa.Services;
using Rebus.Config;
using Rebus.Logging;
using Rebus.Routing.TypeBased;
namespace Elsa.ServiceBus.RabbitMq.Extensions
{
public static class ElsaOptionsExtensions
{
public static ElsaOptions UseRabbitMq(this ElsaOptions elsaOptions, string connectionString, LogLevel logLevel = LogLevel.Info)
{
return elsaOptions.UseServiceBus(context => ConfigureAzureServiceBusEndpoint(context, connectionString, logLevel));
}
private static void ConfigureAzureServiceBusEndpoint(ServiceBusEndpointConfigurationContext context, string connectionString, LogLevel logLevel)
{
var queueName = context.QueueName;
context.Configurer
.Logging(l => l.ColoredConsole(logLevel))
.Transport(t => t.UseRabbitMq(connectionString, queueName))
.Routing(r => r.TypeBased().Map(context.MessageTypeMap));
}
}
}