An Azure ServiceBus transport support for the Obvs framework.
The following Azure ServiceBus messaging entities are currently supported by this transport:
- Queues
- Topics
- Subscriptions
As of Obvs 3.x, the library offers no out-of-the-box control over peek-lock style messages like those you might receive from Azure Service Bus.
Therefore this library offers a small API-subset that is designed to be agnostic of Azure Service Bus at the surface level, yet gives you the
full control you would expect over peek-lock style messages as if you were working with Azure Service Bus's BrokeredMessage
class directly.
Please note: you must opt-in to PeekLock
mode as the default is ReceiveAndDelete
. This is to stay consistent with the Azure Service Bus API itself.
You can read more on this subject here in the Wiki.
The following examples show how you would configure the service bus for a variety of basic scenarios.
Shows how to configure the bus to send commands to an Azure Service Bus Queue.
// Configure the bus with a queue
var serviceBusClient = ServiceBus<MyMessage, MyCommand, MyEvent, MyRequest, MyResponse>.Configure()
.WithAzureServiceBusEndpoint()
.Named("My Service Bus")
.WithConnectionString(ConfigurationManager.AppSettings["MyServiceBusConnectionString"])
.UsingQueueFor<MyCommand>("my-commands")
.SerializedAsJson()
.AsClient()
.CreateServiceBusClient();
// Send a command via the configured client
await serviceBusClient.SendAsync(new MyFancyCommand());
// Configure the bus with a topic
var serviceBus = ServiceBus<MyMessage, MyCommand, MyEvent, MyRequest, MyResponse>.Configure()
.WithAzureServiceBusEndpoint()
.Named("My Service Bus")
.WithConnectionString(ConfigurationManager.AppSettings["MyServiceBusConnectionString"])
.UsingTopicFor<MyEvent>("my-events")
.SerializedAsJson()
.AsServer()
.CreateServiceBus();
// Publish an event via the configured service bus
await serviceBus.PublishAsync(new MySpecialEvent());
// Configure the bus with a specific subscription
var serviceBusClient = ServiceBus<MyMessage, MyCommand, MyEvent, MyRequest, MyResponse>.Configure()
.WithAzureServiceBusEndpoint()
.Named("My Service Bus")
.WithConnectionString(ConfigurationManager.AppSettings["MyServiceBusConnectionString"])
.UsingSubscriptionFor<MyEvent>("my-events", "my-subscription", MessageReceiveMode.PeekLock)
.SerializedAsJson()
.AsClient()
.CreateServiceBusClient();
// Process all events that come in via my subscription
serviceBusClient.Events.Subscribe(myEvent =>
{
// ... handle the incoming event with whatever domain specific logic here ...
// Signal completion of the peek lock
myEvent.GetPeekLockControl().CompleteAsync().Wait();
});