1

I'm exploring the Rebus library. I implemented the Pub/Sub successfully in Microsoft.NET.Sdk.Worker project with FileSystem transport. But I'm struggling to make it work with AzureServiceBus. I have below configuration in Program.cs:

IHost host = Host.CreateDefaultBuilder(args)
        .ConfigureServices((context, services) => {
            services.AddLogging();

            services.AddRebus(
                (config, provider) => {
                    config
                        .Logging(l => l.Console())
                        .Routing(r => r.TypeBased().MapAssemblyOf<CreateNewReportMessage>(busConfig.MainQueue))
                        //.Transport(x => x.UseFileSystem(busConfig.FileSystemTransportBaseDirectory, busConfig.MainQueue))
                        //.Subscriptions(x => x.UseJsonFile(Path.Combine(busConfig.FileSystemTransportBaseDirectory, "rebus_subscriptions.json")))
                        .Transport(x => x.UseAzureServiceBus(busConfig.AzureSBConnectionString, busConfig.MainQueue).AutomaticallyRenewPeekLock());
                    return config;
                },
                onCreated: async bus => {
                    await bus.Subscribe<CreateNewReportMessage>();
                }
            );
            services.AutoRegisterHandlersFromAssemblyOf<Program>();
        })
        .Build();

    await host.RunAsync();

I'm getting below 400 Bad request error. The app is published as Azure WebJob.

INFO] [DBG] Rebus.AzureServiceBus.AzureServiceBusTransport (Thread #1): Registering subscription for topic "MyServiceBus/MyServiceBus.Messages.CreateNewReportMessage"
INFO]       Successfully created bus instance RebusBus Rebus 1 (isDefaultBus: True)
INFO]       Application started. Press Ctrl+C to shut down.
INFO] fail: Microsoft.Extensions.Hosting.Internal.Host[9]
INFO]       BackgroundService failed
INFO]        ---> Azure.RequestFailedException: The specified HTTP verb (GET) is not valid. To know more visit https://aka.ms/sbResourceMgrExceptions. . TrackingId:1808
INFO]       Status: 400 (Bad Request)
INFO]          --- End of inner exception stack trace ---
INFO]          at Azure.Messaging.ServiceBus.Administration.HttpRequestAndResponse.ThrowIfRequestFailedAsync(Request request, Response response)
INFO]          at Azure.Messaging.ServiceBus.Administration.HttpRequestAndResponse.SendHttpRequestAsync(Request request, CancellationToken cancellationToken)
INFO]          at Azure.Messaging.ServiceBus.Administration.HttpRequestAndResponse.GetEntityAsync(String entityPath, String query, Boolean enrich, CancellationToken can
INFO]          at Azure.Messaging.ServiceBus.Administration.ServiceBusAdministrationClient.TopicExistsAsync(String name, CancellationToken cancellationToken)
INFO]          at Rebus.AzureServiceBus.AzureServiceBusTransport.EnsureTopicExists(String normalizedTopic)
INFO]          at Rebus.AzureServiceBus.AzureServiceBusTransport.<>c__DisplayClass25_0.<<RegisterSubscriber>b__0>d.MoveNext()
INFO]       --- End of stack trace from previous location ---
INFO]          at Rebus.Internals.ExceptionIgnorant.Execute(Func`1 function, CancellationToken cancellationToken)
INFO]          at Rebus.Internals.ExceptionIgnorant.Execute(Func`1 function, CancellationToken cancellationToken)
INFO]          at Rebus.AzureServiceBus.AzureServiceBusTransport.RegisterSubscriber(String topic, String subscriberAddress)
INFO]          at Rebus.Bus.RebusBus.InnerSubscribe(String topic)
harry777
  • 61
  • 1
  • 5
  • This is most likely because the connection string you're using lacks the _Manage privilege. You'll need to provide that, so Rebus can help you initialize queues with the correct settings, create topics, and manage subscriptions. – mookid8000 Jan 30 '23 at 15:40
  • Thanks for your reply, I did start to wonder about that. I'll get in touch with infra team and investigate. – harry777 Jan 30 '23 at 15:54
  • Update: The connection string already have Manage level permissions. :( – harry777 Jan 30 '23 at 16:17
  • Has the Endpoint part of the connection string been changed somehow? – mookid8000 Jan 31 '23 at 16:07
  • Interestingly `bus.Advanced.Topics.Subscribe(typeof(CreateNewReportMessage).FullName)` is able to create topic on AzureSB but `bus.Subscribe()` fails with 400 (Bad Request). – harry777 Jan 31 '23 at 17:55
  • That does not make any sense.... UNLESS `typeof(CreateNewReportMessage). typeof(string).GetSimpleAssemblyQualifiedName()` happens to return a string that is too long! Could you maybe check the length of the string returned from that extension method when called on your even type? – mookid8000 Feb 01 '23 at 08:19
  • Do you mean the length of `typeof(CreateNewReportMessage).GetSimpleAssemblyQualifiedName()`, that is only 60 characters long? Just another info - the queues are getting created properly. – harry777 Feb 01 '23 at 10:36
  • I mean check the length of the string returned from `typeof(CreateNewReportMessage).GetSimpleAssemblyQualifiedName()` – it's the "short, assembly-qualified name" of the type, i.e. it includes the name of the assembly and the full namespace in addition to the class name, which COULD end up being too long for ASB, and thus lead to the cheap and silly BadRequest response – mookid8000 Feb 01 '23 at 15:13
  • the string length is just 58 characters "MyServiceBus.Messages.CreateNewReportMessage, MyServiceBus" – harry777 Feb 02 '23 at 07:46
  • Looking through AzureServiceBusTransport code, topic returned by [_nameFormatter.FormatTopicName(topic)](https://github.com/rebus-org/Rebus.AzureServiceBus/blob/master/Rebus.AzureServiceBus/AzureServiceBus/AzureServiceBusTransport.cs#L151) is "MyServiceBus/MyServiceBus.Messages.CreateNewReportMessage" containing '/' which is not accepted topic name in [ASB](https://learn.microsoft.com/en-us/archive/blogs/servicebus/azure-service-bus-azure-resource-manager-and-this-character). 400 bad request was because of that. One work around is to use `.UseLegacyNaming()`. – harry777 Feb 02 '23 at 16:01
  • The '/' is indeed accepted both in queue and in topic names. In some tools (e.g. [ServiceBusExplorer](https://github.com/paolosalvatori/ServiceBusExplorer)) it will display queues and topics as if it was a directory structure when your queues/topics have '/' in them – mookid8000 Feb 03 '23 at 07:35
  • Yes apologies my bad, it mentions on Azure new topic info too `Topic names can contain letters, numbers, periods (.), hyphens (-), underscores (_), and slashes (/), up to 260 characters. Topic names are also case-insensitive.` – harry777 Feb 03 '23 at 07:41

0 Answers0