3

I am looking into Rebus and to use it with Azure Service Bus. Using it with regalure Queues was easy, but when I want to use Topic instead I can't get it to work.

Is there any here that have a done a setup and use it with Topic/Subscription. This is what I have so far.

        static void Main(string[] args)
    {
        _bus1 = InitializeBus(System.Environment.MachineName);
        _bus2 = InitializeBus(System.Environment.MachineName + "_2");
        _bus3 = InitializeBus();

        Run();
        Console.WriteLine("Press Enter to exit!");
        Console.ReadLine();
    }

    private static void Run()
    {
        try
        {
            _bus1.Handle<string>((b, c, m) => { Console.WriteLine(m); return null; });
            _bus2.Handle<string>((b, c, m) => { Console.WriteLine(m); return null; });
            _bus1.Bus.Subscribe<string>();
            _bus2.Bus.Subscribe<string>();
            _bus3.Bus.Publish("Publish test message");
        }
        catch (Exception ex)
        {
            throw;
        }
    }

    private static BuiltinHandlerActivator InitializeBus(string queueName = null)
    {
        var activator = new BuiltinHandlerActivator();

        if(string.IsNullOrEmpty(queueName))
            Configure.With(activator)
                .Transport(t => t.UseAzureServiceBusAsOneWayClient(connectionString))
                .Options(o => { o.SetNumberOfWorkers(10); o.SetMaxParallelism(10); })
                .Start();
        else
            Configure.With(activator)
                .Transport(t => t.UseAzureServiceBus(connectionString, queueName).EnablePartitioning().DoNotCreateQueues())
                .Options(o => { o.SetNumberOfWorkers(10); o.SetMaxParallelism(10); })
                .Start();

        return activator;
    }

First I create all the buses. I am using DontCreateQueues() since I don't want the queues to be duplicated created in my root but only under the Topic as Subscription. Then I set up the buses and the Publish works fine, there is one Topic created and 2 subscriptions created under this Topic, and there is 1 message in each of this subscriptions. But the messages is never collected.

If I remove the DontCreateQueues() method in the Configuration the code work, but then 2 queues are created in the root togheter with the topic and it's 2 subscriptions, but I can't have it like that.

Best Regards Magnus

Magnus Gladh
  • 1,817
  • 4
  • 20
  • 31

1 Answers1

0

Rebus uses topics by creating a subscription for each topic you subscribe to, and then configure the subscription to forward received messages to the input queue of the bus.

If the bus does not have an input queue with the expected name (either one created by Rebus, or one you created manually), things will not work.

The reason DontCreateQueues() exists is to allow for expert users to configure their queue settings beyond what Rebus is capable of (and willing) to do. It requires a pretty detailed knowledge about how Rebus expects your queue entities to be laid out though, so I would recommend almost anyone to NOT create anything manually, and then simply let Rebus set things up.

mookid8000
  • 18,258
  • 2
  • 39
  • 63