Skip to content

Commit b7a29d2

Browse files
committed
Broken out RabbitMq into a separate project and nuget package.
1 parent df45544 commit b7a29d2

File tree

52 files changed

+586
-345
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+586
-345
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@
99
/DS.SimpleServiceBus.ConsoleApp/obj
1010
/DS.SimpleServiceBus.Tests/bin
1111
/DS.SimpleServiceBus.Tests/obj
12+
/DS.SimpleServiceBus.RabbitMq/bin/Release/netstandard2.0
13+
/DS.SimpleServiceBus.RabbitMq/obj

DS.SimpleServiceBus.ConsoleApp/DS.SimpleServiceBus.ConsoleApp.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
</PropertyGroup>
1515

1616
<ItemGroup>
17+
<ProjectReference Include="..\DS.SimpleServiceBus.RabbitMq\DS.SimpleServiceBus.RabbitMq.csproj" />
1718
<ProjectReference Include="..\DS.SimpleServiceBus\DS.SimpleServiceBus.csproj" />
1819
</ItemGroup>
1920

DS.SimpleServiceBus.ConsoleApp/Events/TestEvent.cs

-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ namespace DS.SimpleServiceBus.ConsoleApp.Events
55
{
66
public class TestEvent : Event<TestModel>
77
{
8-
98
}
109
}

DS.SimpleServiceBus.ConsoleApp/Events/TestEvent2.cs

-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ namespace DS.SimpleServiceBus.ConsoleApp.Events
55
{
66
public class TestEvent2 : Event<TestModel>
77
{
8-
98
}
109
}

DS.SimpleServiceBus.ConsoleApp/Program.cs

+9-13
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using DS.SimpleServiceBus.ConsoleApp.Events.EventHandlers;
99
using DS.SimpleServiceBus.ConsoleApp.Events.Models;
1010
using DS.SimpleServiceBus.Factories;
11-
using DS.SimpleServiceBus.Services;
11+
using DS.SimpleServiceBus.RabbitMq.Extensions;
1212

1313
namespace DS.SimpleServiceBus.ConsoleApp
1414
{
@@ -23,30 +23,26 @@ public static async Task MainAsync()
2323
{
2424
Console.WriteLine("Hello World!");
2525

26-
var busService = BusServiceFactory.CreateUsingRabbitMq(cfg =>
26+
var busService = BusServiceFactory.Create.UsingRabbitMq(cfg =>
2727
{
2828
cfg.Uri = "rabbitmq://localhost/dsevents";
2929
cfg.Username = "guest";
3030
cfg.Password = "guest";
3131
});
3232

33-
//var busService = new BusService(cfg =>
34-
//{
35-
// cfg.Uri = "rabbitmq://localhost/dsevents";
36-
// cfg.Username = "guest";
37-
// cfg.Password = "guest";
38-
//});
39-
4033
await busService.StartAsync(CancellationToken.None);
4134

42-
var eventService = new EventService(busService, cfg => cfg.EventQueueName = "ds.events");
35+
var eventService =
36+
EventServiceFactory.Create.UsingRabbitMq(busService, x => x.EventQueueName = "ds.events");
4337
eventService.RegisterEventHandler<TestEventListener>();
4438
eventService.RegisterEventHandler<TestEventListener2>();
4539

46-
var commandService = new CommandService(busService, cfg => cfg.CommandQueueName = "ds.commands");
40+
var commandService =
41+
CommandServiceFactory.Create.UsingRabbitMq(busService, x => x.CommandQueueName = "ds.command");
4742
commandService.RegisterCommandHandler<TestCommandHandler>();
4843

49-
var commandService2 = new CommandService(busService, cfg => cfg.CommandQueueName = "ds.commands2");
44+
var commandService2 =
45+
CommandServiceFactory.Create.UsingRabbitMq(busService, x => x.CommandQueueName = "ds.commands2");
5046
commandService2.RegisterCommandHandler<TestCommandHandler2>();
5147

5248

@@ -57,7 +53,7 @@ await eventService.PublishAsync(new TestEvent
5753

5854
eventService.PublishAsync(new TestEvent2
5955
{
60-
Model = new TestModel { Id = 10, Name = "Andreas" }
56+
Model = new TestModel {Id = 10, Name = "Andreas"}
6157
}, CancellationToken.None).Wait();
6258

6359
var request = new TestRequest {Id = 10};

DS.SimpleServiceBus/Commands/RequestResponseClient.cs DS.SimpleServiceBus.RabbitMq/Commands/RequestResponseClient.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using DS.SimpleServiceBus.Commands.Interfaces;
44
using MassTransit;
55

6-
namespace DS.SimpleServiceBus.Commands
6+
namespace DS.SimpleServiceBus.RabbitMq.Commands
77
{
88
public class RequestResponseClient : IRequestResponseClient
99
{

DS.SimpleServiceBus/Configuration/Interfaces/IRabbitMqBusServiceConfiguration.cs DS.SimpleServiceBus.RabbitMq/Configuration/Interfaces/IRabbitMqBusServiceConfiguration.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace DS.SimpleServiceBus.Configuration.Interfaces
1+
using DS.SimpleServiceBus.Configuration.Interfaces;
2+
3+
namespace DS.SimpleServiceBus.RabbitMq.Configuration.Interfaces
24
{
35
public interface IRabbitMqBusServiceConfiguration : IBusServiceConfiguration
46
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using DS.SimpleServiceBus.Configuration.Interfaces;
2+
3+
namespace DS.SimpleServiceBus.RabbitMq.Configuration.Interfaces
4+
{
5+
public interface IRabbitMqCommandServiceConfiguration : ICommandServiceConfiguration
6+
{
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using DS.SimpleServiceBus.Configuration.Interfaces;
2+
3+
namespace DS.SimpleServiceBus.RabbitMq.Configuration.Interfaces
4+
{
5+
public interface IRabbitMqEventServiceConfiguration : IEventServiceConfiguration
6+
{
7+
}
8+
}

DS.SimpleServiceBus/Configuration/RabbitMQBusServiceConfiguration.cs DS.SimpleServiceBus.RabbitMq/Configuration/RabbitMQBusServiceConfiguration.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using DS.SimpleServiceBus.Configuration.Interfaces;
1+
using DS.SimpleServiceBus.RabbitMq.Configuration.Interfaces;
22

3-
namespace DS.SimpleServiceBus.Configuration
3+
namespace DS.SimpleServiceBus.RabbitMq.Configuration
44
{
55
public class RabbitMqBusServiceConfiguration : IRabbitMqBusServiceConfiguration
66
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using DS.SimpleServiceBus.RabbitMq.Configuration.Interfaces;
2+
3+
namespace DS.SimpleServiceBus.RabbitMq.Configuration
4+
{
5+
public class RabbitMqCommandServiceConfiguration : IRabbitMqCommandServiceConfiguration
6+
{
7+
public RabbitMqCommandServiceConfiguration()
8+
{
9+
}
10+
11+
public RabbitMqCommandServiceConfiguration(string commandQueueName)
12+
{
13+
CommandQueueName = commandQueueName;
14+
}
15+
16+
public string CommandQueueName { get; set; }
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using DS.SimpleServiceBus.RabbitMq.Configuration.Interfaces;
2+
3+
namespace DS.SimpleServiceBus.RabbitMq.Configuration
4+
{
5+
public class RabbitMqEventServiceConfiguration : IRabbitMqEventServiceConfiguration
6+
{
7+
public RabbitMqEventServiceConfiguration()
8+
{
9+
}
10+
11+
public RabbitMqEventServiceConfiguration(string eventQueueName)
12+
{
13+
EventQueueName = eventQueueName;
14+
}
15+
16+
public string EventQueueName { get; set; }
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
6+
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
7+
<Authors>Dennis Hogström</Authors>
8+
<Company>Dennis Software</Company>
9+
<PackageLicenseUrl>https://opensource.org/licenses/MIT</PackageLicenseUrl>
10+
<PackageProjectUrl>https://github.com/dennishog/SimpleServiceBus</PackageProjectUrl>
11+
<RepositoryUrl>https://github.com/dennishog/SimpleServiceBus</RepositoryUrl>
12+
<Version>1.0.6</Version>
13+
<AssemblyVersion>1.0.6.0</AssemblyVersion>
14+
</PropertyGroup>
15+
16+
<ItemGroup>
17+
<PackageReference Include="MassTransit.RabbitMQ" Version="4.0.1" />
18+
</ItemGroup>
19+
20+
<ItemGroup>
21+
<ProjectReference Include="..\DS.SimpleServiceBus\DS.SimpleServiceBus.csproj" />
22+
</ItemGroup>
23+
24+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using DS.SimpleServiceBus.Factories.Interfaces;
3+
using DS.SimpleServiceBus.RabbitMq.Configuration;
4+
using DS.SimpleServiceBus.RabbitMq.Configuration.Interfaces;
5+
using DS.SimpleServiceBus.RabbitMq.Services;
6+
using DS.SimpleServiceBus.Services.Interfaces;
7+
using MassTransit;
8+
using MassTransit.RabbitMqTransport;
9+
10+
namespace DS.SimpleServiceBus.RabbitMq.Extensions
11+
{
12+
public static class BusServiceFactoryExtensions
13+
{
14+
public static IBusService UsingRabbitMq(this IBusServiceFactoryExtensionHook extensionHook,
15+
Action<IRabbitMqBusServiceConfiguration> action)
16+
{
17+
IRabbitMqBusServiceConfiguration configuration = new RabbitMqBusServiceConfiguration();
18+
action(configuration);
19+
20+
IRabbitMqHost host = null;
21+
var bus = Bus.Factory.CreateUsingRabbitMq(cfg =>
22+
{
23+
host = cfg.Host(new Uri(configuration.Uri), h =>
24+
{
25+
h.Username(configuration.Username);
26+
h.Password(configuration.Password);
27+
});
28+
});
29+
30+
return new RabbitMqBusService(bus, host);
31+
}
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using DS.SimpleServiceBus.Factories.Interfaces;
3+
using DS.SimpleServiceBus.RabbitMq.Configuration;
4+
using DS.SimpleServiceBus.RabbitMq.Configuration.Interfaces;
5+
using DS.SimpleServiceBus.RabbitMq.Services;
6+
using DS.SimpleServiceBus.Services.Interfaces;
7+
8+
namespace DS.SimpleServiceBus.RabbitMq.Extensions
9+
{
10+
public static class CommandServiceFactoryExtensions
11+
{
12+
public static ICommandService UsingRabbitMq(this ICommandServiceFactoryExtensionHook extensionHook,
13+
IBusService busService, Action<IRabbitMqCommandServiceConfiguration> action)
14+
{
15+
IRabbitMqCommandServiceConfiguration configuration = new RabbitMqCommandServiceConfiguration();
16+
action(configuration);
17+
18+
return new RabbitMqCommandService(busService, configuration);
19+
}
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using DS.SimpleServiceBus.Factories.Interfaces;
3+
using DS.SimpleServiceBus.RabbitMq.Configuration;
4+
using DS.SimpleServiceBus.RabbitMq.Configuration.Interfaces;
5+
using DS.SimpleServiceBus.RabbitMq.Services;
6+
using DS.SimpleServiceBus.Services.Interfaces;
7+
8+
namespace DS.SimpleServiceBus.RabbitMq.Extensions
9+
{
10+
public static class EventServiceFactoryExtensions
11+
{
12+
public static IEventService UsingRabbitMq(this IEventServiceFactoryExtensionHook extensionHook,
13+
IBusService busService, Action<IRabbitMqEventServiceConfiguration> action)
14+
{
15+
IRabbitMqEventServiceConfiguration configuration = new RabbitMqEventServiceConfiguration();
16+
action(configuration);
17+
18+
return new RabbitMqEventService(busService, configuration);
19+
}
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using DS.SimpleServiceBus.Services.Interfaces;
2+
3+
namespace DS.SimpleServiceBus.RabbitMq.Services.Interfaces
4+
{
5+
public interface IRabbitMqBusService : IBusService
6+
{
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using DS.SimpleServiceBus.Commands.Interfaces;
2+
using MassTransit;
3+
4+
namespace DS.SimpleServiceBus.RabbitMq.Services.Interfaces
5+
{
6+
public interface IRabbitMqCommandService : SimpleServiceBus.Services.Interfaces.ICommandService, IConsumer<ICommandMessage>
7+
{
8+
}
9+
}

DS.SimpleServiceBus/Configuration/Interfaces/IAzureServiceBusBusServiceConfiguration.cs DS.SimpleServiceBus.RabbitMq/Services/Interfaces/IRabbitMqEventService.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
using System.Text;
55
using System.Threading.Tasks;
66

7-
namespace DS.SimpleServiceBus.Configuration.Interfaces
7+
namespace DS.SimpleServiceBus.RabbitMq.Services.Interfaces
88
{
9-
public interface IAzureServiceBusBusServiceConfiguration
9+
public interface IRabbitMqEventService
1010
{
1111

1212
}

0 commit comments

Comments
 (0)