A .NET Standard message bus library that is extensible for simple needs.
See demo project for a working example (with missing configuration).
There are two types of message that are supported, events and commands. For details or understanding, NServiceBus does a great job at explaining it here: https://docs.particular.net/nservicebus/messaging/messages-events-commands.
await bus.Publish(new UserCreated());
await bus.Send(new Email());
- Create a message handler class that implements
IMessageHandler<T>
where T is the command or event class. - Register the message handler directly to RockyBus or using a DI framework.
//Directly to RockyBus
new BusBuilder().AddMessageHandler(() => new RottenAppleCommandHandler());
//Using Microsoft Dependency Injection
new BusBuilder().UseMicrosoftDependencyInjection(p, serviceCollection);
- Define a unique queue name for the handling service that does not conflict with another purpose handling service.
//Azure Service Bus
new BusBuilder()
.UseAzureServiceBus(
ConnectionString,
configuration =>
{
configuration.ReceiveOptions.QueueName = "saturn";
});
Help the bus find the messages and start the bus.
var bus = new BusBuilder()
.DefineCommandScanRuleWith(t => t.Namespace == "RockyBus.DemoMessages" && t.Name.EndsWith("Command"))
.DefineEventScanRuleWith(t => t.Namespace == "RockyBus.DemoMessages" && t.Name.EndsWith("Event"))
.Build();
await bus.Start();
-
Azure Portal
- Create an AAD application.
- In the resource group or subscription -> Access control (IAM), add the AAD application as a contributor role.
-
Getting values
- Subscription ID - can be found on the service bus resource's Overview
- Resource Group Name - can be found on the service bus resource's Overview
- Namespace Name - this is the service bus resource name
- Directory (tenant) ID - can be found on the AAD's application (app that is registered)
- Application (client) ID - can be found on the AAD's application (app that is registered)
- Client Secret - can be generated in AAD's application (app that is registered) under Certificates & secrets
- ConnectionString (used for sending and listening to messages) - can use the
RootManageSharedAccessKey
in the service bus resource's Shared access policy menu.
-
Setting values
new BusBuilder()
.UseAzureServiceBus(
ConnectionString,
configuration =>
{
configuration.SetManagementSettings(SubscriptionId, TenantId, ClientId, ClientSecret, ResourceGroupName, NamespaceName);
});
https://docs.microsoft.com/en-us/azure/active-directory/develop/howto-create-service-principal-portal https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app
- Projects getting into event based architecture may have a harder time justifying NServiceBus and want to get started. Should be easy refactor and transition to NServiceBus when the time is right.
- More simple projects that only requires simple, common messaging patterns.
- Azure Service Bus - https://github.com/Azure-Samples/service-bus-dotnet-management
- PubSub Pattern
- Command Message
- Microsoft.Extensions.DependencyInjection
- .NET Core 2.0
- ??
Feel free to reach out to contribute.