https://github.com/shuttle/shuttle.esb
A highly extensible service bus implementation.
https://github.com/shuttle/shuttle.esb
msmq queue queueing rabbitmq service-bus
Last synced: 8 months ago
JSON representation
A highly extensible service bus implementation.
- Host: GitHub
- URL: https://github.com/shuttle/shuttle.esb
- Owner: Shuttle
- License: bsd-3-clause
- Created: 2014-10-24T12:17:17.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2025-03-02T14:05:23.000Z (10 months ago)
- Last Synced: 2025-05-12T16:57:11.422Z (8 months ago)
- Topics: msmq, queue, queueing, rabbitmq, service-bus
- Language: C#
- Homepage: http://shuttle.github.io/shuttle-esb/
- Size: 1.96 MB
- Stars: 96
- Watchers: 17
- Forks: 30
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Documentation
Please visit the [Shuttle.Esb documentation](https://www.pendel.co.za/shuttle-esb/home.html) for more information.
# Getting Started
Start a new **Console Application** project. We'll need to install one of the support queue implementations. For this example we'll use `Shuttle.Esb.AzureStorageQueues` which can be hosted locally using [Azurite](https://learn.microsoft.com/en-us/azure/storage/common/storage-use-azurite?tabs=visual-studio%2Cblob-storage):
```
PM> Install-Package Shuttle.Esb.AzureStorageQueues
```
We'll also make use of the [.NET generic host](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/generic-host):
```
PM> Install-Package Microsoft.Extensions.Hosting
```
Next we'll implement our endpoint in order to start listening on our queue:
``` c#
internal class Program
{
static async Task Main(string[] args)
{
await Host.CreateDefaultBuilder()
.ConfigureServices(services =>
{
services
.AddServiceBus(builder =>
{
builder.Options.Inbox.WorkQueueUri = "azuresq://azure/work";
// Delegates may also be added to the builder, including adding dependencies
builder.AddMessageHandler(async (IHandlerContext context, ISomeDependency instance) =>
{
Console.WriteLine($@"[some-message] : guid = {context.Message.Guid}");
await Task.CompletedTask;
});
})
.AddAzureStorageQueues(builder =>
{
builder.AddOptions("azure", new AzureStorageQueueOptions
{
ConnectionString = "UseDevelopmentStorage=true;"
});
});
})
.Build()
.RunAsync();
}
}
```
Even though the options may be set directly as above, typically one would make use of a configuration provider:
```c#
internal class Program
{
private static async Task Main(string[] args)
{
await Host.CreateDefaultBuilder()
.ConfigureServices(services =>
{
var configuration =
new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.Build();
services
.AddSingleton(configuration)
.AddServiceBus(builder =>
{
configuration
.GetSection(ServiceBusOptions.SectionName)
.Bind(builder.Options);
})
.AddAzureStorageQueues(builder =>
{
builder.AddOptions("azure", new AzureStorageQueueOptions
{
ConnectionString = configuration
.GetConnectionString("azure")
});
});
})
.Build()
.RunAsync();
}
}
```
The `appsettings.json` file would be as follows (remember to set to `Copy always`):
```json
{
"ConnectionStrings": {
"azure": "UseDevelopmentStorage=true;"
},
"Shuttle": {
"ServiceBus": {
"Inbox": {
"WorkQueueUri": "azuresq://azure/work",
}
}
}
}
```
### Send a command message for processing
``` c#
await serviceBus.SendAsync(new RegisterMember
{
UserName = "user-name",
EMailAddress = "user@domain.com"
});
```
### Publish an event message when something interesting happens
Before publishing an event one would need to register an `ISubscrtiptionService` implementation such as [Shuttle.Esb.Sql.Subscription](/implementations/subscription/sql.md).
``` c#
await serviceBus.PublishAsync(new MemberRegistered
{
UserName = "user-name"
});
```
### Subscribe to those interesting events
``` c#
services.AddServiceBus(builder =>
{
builder.AddSubscription();
});
```
### Handle any messages
``` c#
public class RegisterMemberHandler : IMessageHandler
{
public RegisterMemberHandler(IDependency dependency)
{
}
public async Task ProcessMessageAsync(IHandlerContext context)
{
// perform member registration
await context.PublishAsync(new MemberRegistered
{
UserName = context.Message.UserName
});
}
}
```
``` c#
public class MemberRegisteredHandler : IMessageHandler
{
public async Task ProcessMessageAsync(IHandlerContext context)
{
// processing
}
}
```