Skip to content

Latest commit

 

History

History
76 lines (61 loc) · 2.82 KB

README.md

File metadata and controls

76 lines (61 loc) · 2.82 KB

FluentServiceBus

Release Status NuGet Version NuGet Downloads

FluentServiceBus is an library aiming to help setup Azure ServiceBus using an Fluent/LINQ like API.

Queues

var client = new ServiceBusClient(connectionString);
var administrationClient = new ServiceBusAdministrationClient(connectionString);

await new ServiceBusBuilder()
    .AddQueue(new QueueName("test-queue"))
    .Build(client, administrationClient);

Topics

new ServiceBusBuilder()
    .AddTopic(new TopicName("test-topic"))
        .AddSubscription(new SubscriptionName("test-subscription"))
        .AddSubscription(new SubscriptionName("test-subscription-2"))

Consumers

new ServiceBusBuilder()
    .AddQueue(new QueueName("test-queue"))
        .WithConsumer<Message>(message => Result.Or<Abandon>.Success)
    .AddTopic(new TopicName("test-topic"))
        .AddSubscription(new SubscriptionName("test-subscription"))
             .WithConsumer<Message>(message => Result.Or<Abandon>.Success)
        .AddSubscription(new SubscriptionName("test-subscription-2"))
            .WithConsumer<Message>(message => Result.Or<Abandon>.Success)

Publishers

var built = await new ServiceBusBuilder()
      .AddQueue(new QueueName("test-queue"))
          .AddPublisher(out var testQueueSender)
      .AddTopic(new TopicName("test-topic"))
          .AddPublisher(out var testTopicSender)
          .AddSubscription(new SubscriptionName("test-subscription"))
      .Build(client, administrationClient);

await testQueueSender.GetSender(built).Publish(new { Message = "TestQueueMessage" });
await testTopicSender.GetSender(built).Publish(new { Message = "TestTopicMessage" });

Routing

var router = await new ServiceBusBuilder()
      .AddQueue(new QueueName("test-queue"))
          .WithConsumer<Message>(message => Result.Or<Abandon>.Success)
      .AddTopic(new TopicName("test-topic"))
          .AddSubscription(new SubscriptionName("test-subscription"))
          .AddSubscription(new SubscriptionName("test-subscription-2"))
              .WithConsumer<Message>(message => Result.Or<Abandon>.Success)
      .AddQueue(new QueueName("test-qeueue-2"))
      .BuildRouterWithStore(client, administrationClient)
      .Router;

await router.Publish(new { Message = "TestMessage" }, "test-topic");

Samples

src/Sample/Program.cs

License

The code in this repo is licensed under the MIT license.