Azure服务总线超时异常与NancyFX

本文关键字:NancyFX 异常 超时 服务 总线 Azure | 更新日期: 2023-09-27 18:04:41

我有一个NancyFX API,当其中一个端点被命中时,我需要启动一个与端点本身解耦的长时间运行的异步任务。所以我尝试使用Azure Service Bus队列。

NancyFX端点被击中时,我成功地将消息写入队列。我还可以成功地从NancyFX以外的其他地方订阅和读取队列(我在Linqpad上进行了测试)。

但是,如果我尝试从NancyFX应用程序订阅,我会在启动应用程序的一秒钟或两秒钟内获得超时异常。我正在另一个线程中执行此操作,该线程从NancyFX Bootstrapper.ApplicationStartup覆盖中启动。

我不确定为什么这与在NancyFX应用程序中不这样做不同。我在web.config文件中看不到任何相关的东西。

下面是我用来订阅队列的代码…

var tokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider("Main", AccessKey);
var factory = await MessagingFactory.CreateAsync("sb://myapp.servicebus.windows.net", tokenProvider);
var receiver = await factory.CreateMessageReceiverAsync("MyQueue");
receiver.OnMessage(bm =>
{
    // Do something here
}, new OnMessageOptions
{
    MaxConcurrentCalls = 1,
});

下面是例外…

System.ServiceModel.FaultException ' 1 [System.ServiceModel。ExceptionDetail]:操作超时。b6b8e25a-714f-4f55-8a79-91e390f47a96_G25 (Fault Detail等于一个ExceptionDetail,可能由IncludeExceptionDetailInFaults=true创建,其值为:系统。TimeoutException:操作超时。) .

当我在调试器中捕获它时,这里是调用堆栈…

Microsoft.ServiceBus.dll ! Microsoft.ServiceBus.Messaging.Sbmp.DuplexRequestBindingElement.DuplexRequestSessionChannel.ThrowIfFaultMessage (System.ServiceModel.Channels。第463行c#Microsoft.ServiceBus.dll ! Microsoft.ServiceBus.Messaging.Sbmp.DuplexRequestBindingElement.DuplexRequestSessionChannel.HandleMessageReceived(系统。第313行c#Microsoft.ServiceBus.dll ! Microsoft.ServiceBus.Messaging.Sbmp.DuplexRequestBindingElement.DuplexRequestSessionChannel.OnMessageReceived(系统。第381行c#System.ServiceModel.Internals.dll ! System.Runtime.AsyncResult。Complete(bool completedsynchronous)未知System.ServiceModel.dll ! System.ServiceModel.Channels.TransportDuplexSessionChannel.TryReceiveAsyncResult.OnReceive(系统。IAsyncResult result)未知System.ServiceModel.Internals.dll ! System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(系统。IAsyncResult result)未知System.ServiceModel.Internals.dll ! System.Runtime.AsyncResult。Complete(bool completedsynchronous)未知System.ServiceModel.dll ! System.ServiceModel.Channels.SynchronizedMessageSource.ReceiveAsyncResult。onreceivcomplete(对象状态)未知System.ServiceModel.dll ! System.ServiceModel.Channels.SessionConnectionReader。OnAsyncReadComplete(对象状态)未知System.ServiceModel.Internals.dll ! System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(系统。IAsyncResult result)未知System.dll ! System.Net.LazyAsyncResult.Complete(系统。IntPtr userToken)未知System.dll ! System.Net.LazyAsyncResult。(对象结果,系统。IntPtr userToken)未知System.dll ! System.Net.Security._SslStream。ProcessFrameBody(int readBytes, byte[] buffer, int offset, int count, System.Net.AsyncProtocolRequest)未知System.dll ! System.Net.Security._SslStream.ReadFrameCallback (System.Net。AsyncProtocolRequest(异步请求)未知System.dll ! System.Net.AsyncProtocolRequest。完整请求(int结果)未知System.dll ! System.Net.FixedSizeReader。CheckCompletionBeforeNextRead(int bytes)未知System.dll ! System.Net.FixedSizeReader.ReadCallback(系统。IAsyncResult transportResult)未知System.ServiceModel.Internals.dll ! System.Runtime.AsyncResult。Complete(bool completedsynchronous)未知System.ServiceModel.dll ! System.ServiceModel.Channels.ConnectionStream.IOAsyncResult。OnAsyncIOComplete(对象状态)未知System.dll ! System.Net.Sockets.SocketAsyncEventArgs.OnCompleted (System.Net.Sockets。SocketAsyncEventArgs e)未知System.dll ! System.Net.Sockets.SocketAsyncEventArgs.FinishOperationSuccess (System.Net.Sockets。SocketError, int bytestransered, System.Net.Sockets.SocketFlags flags)未知System.dll ! System.Net.Sockets.SocketAsyncEventArgs。CompletionPortCallback(uint errorCode, uint numBytes, System.Threading)NativeOverlapped* NativeOverlapped)未知mscorlib.dll ! System.Threading._IOCompletionCallback。PerformIOCompletionCallback(uint errorCode, uint numBytes, System.Threading)NativeOverlapped* overllap)未知[Native to Managed Transition]

Azure服务总线超时异常与NancyFX

您得到的异常是客户端无法通过ASB网关与后端通信的指示。您可以使用提供的跟踪ID (b6b8e25a-714f-4f55-8a79-91e390f47a96_G25)来打开一个支持案例。如果异常仍然存在,请尝试使用不同的名称空间,看看是否可以排除该异常。