Rebus: Could not resolve Rebus.Bus.IBus with decorator depth 0 - registrations: Rebus.Injection.Injectionist+Handler"

1.4k Views Asked by At

Getting error while working with Azuer Service Bus, if I use MSMQ queue then no error, so please suggest what is wrong with code or any missing configuration?

Note: Below Rebus initialization code is running under web applcatication:

        _adapter = new BuiltinHandlerActivator();
        _adapter.Register(() => new HubHandler());
        var configurer = Configure.With(_adapter)
                 .Options(o =>
                 {
                     o.SetNumberOfWorkers(RebusConfigSettings.Workers);
                     o.SimpleRetryStrategy(maxDeliveryAttempts: RebusConfigSettings.RetryAttempts);
                 })
                 .Logging(l => l.Log4Net())
                 .Routing(r => r.TypeBasedRoutingFromAppConfig())
                 .Events(x =>
                 {
                     x.BeforeMessageSent += (bus, headers, message, context) =>
                     {
                         if (RebusConfigSettings.TimeToBeReceived != "-1")
                         {
                             headers.Add(Headers.TimeToBeReceived, RebusConfigSettings.TimeToBeReceived);
                             headers.Add(Headers.Express, "rebus-express");
                         }
                     };
                 });
        string azureServiceBusUrl = EnvironmentVariablesManager.GetEnvironmentVariable("AzureServiceBusUrl");
        configurer.Transport(t => t.UseAzureServiceBus(azureServiceBusUrl, RebusConfigSettings.InputQueue)).Start();

Implementation of HubHandler class

public class HubHandler: IHandleMessages<AuthenticationResponse>
{
    public HubHandler() { }


    public async Task Handle(AuthenticationResponse message)
    {
        //...
    }
}

Inner exception:

The remote server returned an error: (401) Unauthorized. Invalid TLS version. TrackingId:4236d339-2355-4074-b187-9d07904ddb30_G62, SystemTracker:jkc-development.servicebus.windows.net:queuename, Timestamp:2022-06-13T13:34:08

1

There are 1 best solutions below

0
Kanu Dhakhada On

It was problem with TLS version, in Azure it was set to 1.2 (Service Bus--> Configuration --> Security) and where in web config, httpRuntime-->targetFramework was set to 4.5.

So after changing .net framework from 4.5 to 4.7.2 in web project then it is started working.