我们面临 Azure Web 应用程序中托管的 Web API 问题。我们正在 Azure 服务总线中插入一条消息。通过 Azure Web 应用程序将消息发送到服务总线队列时出现间歇性超时问题,但在本地调试相同的代码时它工作正常。两种情况下的服务总线是相同的。无法找到相同的原因。下面是代码片段。
Logger.Log(ErrorLevel.Info, "Started Sending Message to Service Bus for Job Id :" + newjobObject.JobId);
ServiceBusRepository.SendMessageToQueue(jobEntity.JobId);
Logger.Log(ErrorLevel.Info, "Completed Sending Message to Service Bus for Job Id :" + newjobObject.JobId);
这是 SendMessageToQueue 方法的代码
public static void SendMessageToQueue(string Message)
{
try
{
var message = new BrokeredMessage(Message);
Logger.Log(ErrorLevel.Info,"Before SendMessagetoQueue= " + message);
sendQueueClient.Send(message);
Logger.Log(ErrorLevel.Info,"After SendMessagetoQueue= " + message);
}
catch(Exception ex)
{
Logger.Log(ex.Message.ToString());
}
}
在日志中,仅记录第一个日志语句,而不是第二个日志语句。所以这意味着在发送消息时发生了一些异常。任何人都可以提供调试此问题的指针。
最佳答案
间歇性超时异常 (System.TimeoutException
) 是暂时性异常,是可接受的。根据documentation ,您应该为任何 transient 异常添加重试逻辑。
除此之外,对于超时异常,您可能需要调整消息传递工厂设置(请参阅 documentation here )。
当客户端抛出异常时,密切关注该异常。它将包含可以提供帮助的信息。将其与问题一起发布不会有什么坏处。
关于从 Azure Web 应用程序发送消息时 Azure ServiceBus 超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48510558/