2

I am new to Rebus, I am looking for code sample for using Rebus with Azure Service Bus, Queue and Topic.

I cannot see it from the link below: https://github.com/rebus-org/RebusSamples

Update

To start off: Sample of enqueuing and dequeuing messaging to Azure Service Bus for Queue, and Topic, configuration.

Ideally, cover more areas of Azure service bus, if possible.

Pingpong
  • 7,681
  • 21
  • 83
  • 209

1 Answers1

2

if you want to use Azure Service Bus with Rebus, you can literally get going with something as simple as

services.AddRebus(
    configure => configure
        .Transport(t => t.UseAzureServiceBus(connectionString, "my_queue"))
);

using Rebus.ServiceProvider with Microsoft's generic host, or

Configure.With(activator)
    .Transport(t => t.UseAzureServiceBus(connectionString, "my_queue"))
    .Start();

where activator is either Rebus' BuiltinHandlerActivator, or a container adapter for your favorite IoC container.

You might want to check out the wiki page about the Azure Service Bus transport – it shows the basics of the configuration, and also explains some more stuff about e.g. long-running message handlers.

mookid8000
  • 18,258
  • 2
  • 39
  • 63
  • I came across the link https://github.com/rebus-org/Rebus/wiki/Azure-Service-Bus-transport before I posted the question here. I thought there were samples from this link https://github.com/rebus-org/RebusSamples. Are there samples that are not showing Azure Service Bus, but can be used for Azure Service Bus with some modification? – Pingpong Apr 10 '19 at 22:48
  • Pretty much all of the samples can be changed to use Azure Service Bus, if you replace whichever `.Transport(t => t.Use...)` is there with `.Transport(t => t.UseAzureServiceBus(...))` – although you will need to remove some parts, if they're also configured, like `.Subscriptions(s => ..)`, because Azure Service Bus does not need that configuration due to built-in pub/sub – mookid8000 Apr 11 '19 at 05:45
  • I was also looking for a working Azure Service Bus example, and tried to apply @mookid8000 's suggestion and updated the RabbitTopics sample application to use Azure ServiceBus. When I then start the program, I see the following error in the console: An error occurred when attempting to receive the next message: "System.InvalidOperationException: Operation is not valid due to the current state of the object." – Sipke Schoorstra Nov 22 '20 at 12:34
  • I'll create an issue for this with more details. – Sipke Schoorstra Nov 22 '20 at 12:36
  • Should I use topics? Or just queues? – Enrico Jul 04 '23 at 09:59
  • 1
    @Enrico depends on a bunch of things e.g. if you can say that the message is a COMMAND (i.e. it's instructing someone to do something), then send it to a queue – if you can say that the message represents an EVENT (i.e. a description of something that has happened), then publish it... when you think some more about these things, you'll find that many of your message types are either commands or events – mookid8000 Jul 05 '23 at 12:21