401 error on Azure Service Bus

408 views
Skip to first unread message

js03...@gmail.com

unread,
Oct 26, 2018, 1:53:46 AM10/26/18
to masstransit-discuss
Hi,

We're migrating our web application to azure cloud and switching from RabbitMQ to Azure Service Bus.

We don't have any issue using RabbitMQ in azure. However, we're having problem to send message to azure service bus. All messages went to _skipped queue and I see following errors

<Error>
<Code>401</Code>
<Detail>
claim is empty. TrackingId:e0327ddb-bcd2-4d6c-ab73-7eaa6a7c6f52_G27, SystemTracker:******.servicebus.windows.net:testqueue_skipped, Timestamp:10/26/2018 5:35:56 AM
</Detail>
</Error>

Our web application is .net core based. The MassTransit packages we installed

1. Masstransit.Azure.ServiceBus.Core v5.1.5
2. Masstransit.Extensions.Dependencyinjection v5.1.5

For testing purpose, i've downloaded sample code from following URL and updated the code to use azure service bus instead of RabbitMQ


Here is the updated code to use Azure Service Bus:

using GreenPipes;
using MassTransit;
using MassTransit.Azure.ServiceBus.Core;
using MassTransit.ExtensionsDependencyInjectionIntegration;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;

namespace WebApplication1
{
    public class Startup
    {
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            services.AddScoped<IService, Service>();
            services.AddScoped<DoSomethingConsumer>();

            services.AddMassTransit(x =>
            {
                // add the consumer, for LoadFrom
                x.AddConsumer<DoSomethingConsumer>();
            });

            //services.AddSingleton(provider => Bus.Factory.CreateUsingRabbitMq(cfg =>
            //{
            //    var host = cfg.Host("localhost", "/", h => { });

            //    cfg.ReceiveEndpoint(host, "web-service-endpoint", e =>
            //    {
            //        e.PrefetchCount = 16;
            //        e.UseMessageRetry(x => x.Interval(2, 100));

            //        e.LoadFrom(provider);

            //        EndpointConvention.Map<DoSomething>(e.InputAddress);
            //    });
            //}));

            services.AddSingleton(provider => Bus.Factory.CreateUsingAzureServiceBus(cfg =>
            {
                var host = cfg.Host("Endpoint=sb://***MyNameSpace***.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=*****MyKey******=", configurator =>
                {
                    configurator.OperationTimeout = TimeSpan.FromSeconds(5);
                });

                //cfg.UseExtensionsLogging(loggerFactory);

                cfg.ReceiveEndpoint(host, "testqueue", e =>
                {
                    e.PrefetchCount = 1;
                    e.UseMessageRetry(x => x.Interval(2, 100));

                    e.LoadFrom(provider);

                    EndpointConvention.Map<DoSomething>(e.InputAddress);
                });
            }));

            services.AddSingleton<IPublishEndpoint>(provider => provider.GetRequiredService<IBusControl>());
            services.AddSingleton<ISendEndpointProvider>(provider => provider.GetRequiredService<IBusControl>());
            services.AddSingleton<IBus>(provider => provider.GetRequiredService<IBusControl>());

            services.AddScoped(provider => provider.GetRequiredService<IBus>().CreateRequestClient<DoSomething>());

            services.AddSingleton<IHostedService, BusService>();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            app.UseMvc();
        }
    }
}

When i run the app, I got following response 

Received: Hello, World., MessageId: 03d70000-e519-1062-b4d1-08d63b05f494

However, the message doesn't seem to have been sent to intended queue - 'testqueue'. I suspect the error has something to do with SAS authorisation and SAS token was not properly set.

I would appreciate if someone could help.

Thanks

James

James Smith

unread,
Oct 27, 2018, 2:39:46 AM10/27/18
to masstransit-discuss
Finally get it working.

        services.AddSingleton(provider => Bus.Factory.CreateUsingAzureServiceBus(cfg =>
            {
                var host = cfg.Host("Endpoint=sb://NAMESPACE.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=KEYHERE****=", configurator =>
                {
                    configurator.OperationTimeout = TimeSpan.FromSeconds(5);
                });
            }));


 
Reply all
Reply to author
Forward
0 new messages