带有 AzureServiceBus 的 MassTransit 3 在队列名称前加上斜杠

MassTransit 3 with AzureServiceBus prefixing a slash to queue names

当我尝试使用 MassTransit 3运行 我在 Azure 中的应用程序时出现以下错误

The entity name or path cannot contain '/' as prefix or suffix. The supplied value is '/profile.api'. Parameter name: entityName

我可以看到前缀被添加到队列名称的唯一方法是通过 MassTransit。

奇怪的是,队列已在我的 Azure 门户中创建,名称为 "profile.api"。

有没有其他人遇到过这种情况?我不确定这是 MassTransit 的错误还是我在配置中遗漏了一个步骤。

完整的堆栈跟踪如下。

谢谢。

[ArgumentException: The entity name or path cannot contain '/' as prefix or suffix. The supplied value is '/profile.api'. Parameter name: entityName]
Microsoft.ServiceBus.Common.AsyncResult.End(IAsyncResult result) +381 Microsoft.ServiceBus.Messaging.MessagingFactory.EndCreateMessageReceiver(IAsyncResult result) +70
System.Threading.Tasks.TaskFactory1.FromAsyncCoreLogic(IAsyncResult iar, Func2 endFunction, Action1 endAction, Task1 promise, Boolean requiresSynchronization) +86
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
MassTransit.AzureServiceBusTransport.Pipeline.-Send>d__7.MoveNext() +794 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +26 MassTransit.AzureServiceBusTransport.Pipeline.-Send>d__7.MoveNext() +2756 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
MassTransit.AzureServiceBusTransport.Pipeline.d__5.MoveNext() +1599 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
MassTransit.AzureServiceBusTransport.<b__0>d.MoveNext() +531 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
MassTransit.Internals.Extensions.d__01.MoveNext() +924 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99<br> System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58 MassTransit.<StartAsync>d__29.MoveNext() +1154<br> System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +26<br> MassTransit.<StartAsync>d__29.MoveNext() +2025<br> System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99<br> System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58 MassTransit.Util.TaskUtil.Await(Func1 taskFactory, CancellationToken cancellationToken) +222
MassTransit.MassTransitBus.MassTransit.IBusControl.Start() +61
SampleApp.Startup.ConfigureBus() +33
SampleApp.Startup.Configuration(IAppBuilder app) +428

事实证明,与 MassTransit 测试 运行 天蓝色配置的方式相比,我的应用程序的配置方式存在非常细微的差异。

而我 (不起作用)

public class AzureBusModule : Autofac.Module
{
    protected override void Load(ContainerBuilder builder)
    {
        builder.Register(context =>
        {
            var busControl = Bus.Factory.CreateUsingAzureServiceBus(sbc =>
            {
                var host = sbc.Host(new Uri("sb://" + ConfigurationManager.AppSettings["AzureEndPoint"]), h =>
                {
                    h.OperationTimeout = TimeSpan.FromSeconds(5);
                    h.TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(
                        ConfigurationManager.AppSettings["AzureKeyName"],
                        ConfigurationManager.AppSettings["AzureKeyValue"]);
                });

                sbc.UseSerilog();
                sbc.UseJsonSerializer();
                //sbc.UseRetry(Retry.Exponential(10.Seconds(), 3.Minutes(), 10.Seconds()));

                sbc.ReceiveEndpoint(host, ConfigurationManager.AppSettings["QueueName"], ep =>
                {
                    ep.LoadFrom(context);
                });

            });

            Log.Information("Finished Configuring MassTransit using Azure");

            return busControl;
        })
        .SingleInstance()
        .As<IBusControl>()
        .As<IBus>();
    }
}

更改以下内容解决了我的问题。

var serviceUri = ServiceBusEnvironment.CreateServiceUri("sb",
    ConfigurationManager.AppSettings["AzureEndpoint"],
    ConfigurationManager.AppSettings["AzureEndpointName"]);

var host = sbc.Host(serviceUri, h =>
{
    // [...]
}

我希望这对遇到类似问题的其他人有所帮助。