在将MassTransit传输设置为Azure Service Bus的情况下引发消息时,会引发以下异常并将错误放置在错误队列中:
Put token failed. status-code: 404, status-description:
The messaging entity 'sb://xxxx-prod-bus.servicebus.windows.net/Api/StateMachine-MessageEvent' could not be found.
但是,如果传奇再次运行,则消息已成功发布。在查看了试图将消息发布到的主题之后,第一次不存在该主题,但是似乎随后创建了该主题,但是,将该主题的Auto Delete On Idle
属性设置为5分钟,因此闲置一段时间后,主题消失,错误再次出现。
使用接口和用于包装传奇实例状态的类型将消息合同声明为与MassTransit文档(https://masstransit-project.com/usage/sagas/automatonymous.html#publish)完全相同:
public interface ExampleMessage
{
Guid OrderId { get; }
}
private class ExampleMessageEvent :
ExampleMessage
{
public ExampleMessageEvent(Instance instance)
{
SomeProp = instance.SomeProp;
}
public string SomeProp { get; }
}
其他处理程序仅订阅ExampleMessage
的接口,因此我希望即使没有人在concreate类型主题上进行监听,发布也将继续进行?
避免这些问题的最佳方法是什么?我尝试使用重试来查看它是否重新创建了交换,但是重试没有任何创建。
似乎临时主题的默认值是从here起5分钟 。但是,我希望,如果在发布消息时不存在该主题,它将再次被创建?
引发的完整异常消息是:
Put token failed. status-code: 404, status-description: The messaging entity 'sb://something-prod-bus.servicebus.windows.net/Something.Api/SomethingStateMachine-SomethingRequiredEvent' could not be found. To know more visit https://aka.ms/sbResourceMgrExceptions. TrackingId:2f9c9776-08d5-41ab-81ba-3ec9011c2a90_G49, SystemTracker:something-prod-bus.servicebus.windows.Something.Api/SomethingStateMachine-SomethingRequiredEvent, Timestamp:2019-12-13T23:13:46.
以及完整的堆栈跟踪:
Microsoft.Azure.ServiceBus.MessagingEntityNotFoundException:
at Microsoft.Azure.ServiceBus.Core.MessageSender+<OnSendAsync>d__58.MoveNext (Microsoft.Azure.ServiceBus, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7e34167dcc6d6d8c)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Azure.ServiceBus.RetryPolicy+<RunOperation>d__19.MoveNext (Microsoft.Azure.ServiceBus, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7e34167dcc6d6d8c)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Azure.ServiceBus.RetryPolicy+<RunOperation>d__19.MoveNext (Microsoft.Azure.ServiceBus, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7e34167dcc6d6d8c)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Azure.ServiceBus.Core.MessageSender+<SendAsync>d__45.MoveNext (Microsoft.Azure.ServiceBus, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7e34167dcc6d6d8c)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at MassTransit.Azure.ServiceBus.Core.Transport.ServiceBusSendTransport+SendClientPipe`1+<Send>d__5.MoveNext (MassTransit.Azure.ServiceBus.Core, Version=5.5.6.0, Culture=neutral, PublicKeyToken=b8e0e9f2f1e657fa)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at MassTransit.Azure.ServiceBus.Core.Transport.ServiceBusSendTransport+SendClientPipe`1+<Send>d__5.MoveNext (MassTransit.Azure.ServiceBus.Core, Version=5.5.6.0, Culture=neutral, PublicKeyToken=b8e0e9f2f1e657fa)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at GreenPipes.Agents.PipeContextSupervisor`1+<GreenPipes-IPipeContextSource<TContext>-Send>d__8.MoveNext (GreenPipes, Version=2.1.4.118, Culture=neutral, PublicKeyToken=b800c4cfcdeea87b)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at GreenPipes.Agents.PipeContextSupervisor`1+<GreenPipes-IPipeContextSource<TContext>-Send>d__8.MoveNext (GreenPipes, Version=2.1.4.118, Culture=neutral, PublicKeyToken=b800c4cfcdeea87b)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at GreenPipes.Agents.PipeContextSupervisor`1+<GreenPipes-IPipeContextSource<TContext>-Send>d__8.MoveNext (GreenPipes, Version=2.1.4.118, Culture=neutral, PublicKeyToken=b800c4cfcdeea87b)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at MassTransit.Transports.PublishEndpoint+<Publish>d__17`1.MoveNext (MassTransit, Version=5.5.6.0, Culture=neutral, PublicKeyToken=b8e0e9f2f1e657fa)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at MassTransit.Transports.PublishEndpoint+<Publish>d__17`1.MoveNext (MassTransit, Version=5.5.6.0, Culture=neutral, PublicKeyToken=b8e0e9f2f1e657fa)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at MassTransit.Context.InMemoryOutboxConsumeContext+<ExecutePendingActions>d__10.MoveNext (MassTransit, Version=5.5.6.0, Culture=neutral, PublicKeyToken=b8e0e9f2f1e657fa)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at MassTransit.Pipeline.Filters.InMemoryOutboxFilter`1+<Send>d__1.MoveNext (MassTransit, Version=5.5.6.0, Culture=neutral, PublicKeyToken=b8e0e9f2f1e657fa)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at MassTransit.Pipeline.Filters.InMemoryOutboxFilter`1+<Send>d__1.MoveNext (MassTransit, Version=5.5.6.0, Culture=neutral, PublicKeyToken=b8e0e9f2f1e657fa)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at MassTransit.ApplicationInsights.Pipeline.ApplicationInsightsConsumeFilter`1+<Send>d__14.MoveNext (MassTransit.ApplicationInsights, Version=5.5.6.0, Culture=neutral, PublicKeyToken=b8e0e9f2f1e657fa)
答案 0 :(得分:1)
由于使用的类实现了已发布的接口,因此需要将其发布为实际的消息接口。我猜想您上面的示例遗漏的一件事是ExampleMessageEvent
类实际上是私有的(或内部的)。
在传奇中发布时,请将类强制转换为接口类型,以便它不会为该类创建临时主题。
.Publish(context => (ExampleMessage)new ExampleMessageEvent(...));