首页 > 解决方案 > 发送消息时服务总线未知错误 (0xffffffff)

问题描述

我有一个连接到服务总线队列的 Azure 应用服务 API。一切都工作了一段时间,但后来我开始遇到这些错误:

System.AggregateException: One or more errors occurred. (Unknown error (0xffffffff) ErrorCode: SocketError) ---> Microsoft.Azure.ServiceBus.ServiceBusCommunicationException: Unknown error (0xffffffff) ErrorCode: SocketError ---> System.Net.Sockets.SocketException: Unknown error (0xffffffff)
   at Microsoft.Azure.ServiceBus.ServiceBusConnection.CreateConnectionAsync(TimeSpan timeout)
   at Microsoft.Azure.Amqp.FaultTolerantAmqpObject`1.OnCreateAsync(TimeSpan timeout)
   at Microsoft.Azure.Amqp.Singleton`1.GetOrCreateAsync(TimeSpan timeout)
   at Microsoft.Azure.Amqp.Singleton`1.GetOrCreateAsync(TimeSpan timeout)
   at Microsoft.Azure.ServiceBus.Amqp.AmqpLinkCreator.CreateAndOpenAmqpLinkAsync()
   at Microsoft.Azure.ServiceBus.Core.MessageSender.CreateLinkAsync(TimeSpan timeout)
   at Microsoft.Azure.Amqp.FaultTolerantAmqpObject`1.OnCreateAsync(TimeSpan timeout)
   at Microsoft.Azure.Amqp.Singleton`1.GetOrCreateAsync(TimeSpan timeout)
   at Microsoft.Azure.Amqp.Singleton`1.GetOrCreateAsync(TimeSpan timeout)
   at Microsoft.Azure.ServiceBus.Core.MessageSender.OnSendAsync(IList`1 messageList)
   --- End of inner exception stack trace ---
   at Microsoft.Azure.ServiceBus.Core.MessageSender.OnSendAsync(IList`1 messageList)
   at Microsoft.Azure.ServiceBus.RetryPolicy.RunOperation(Func`1 operation, TimeSpan operationTimeout)
   at Microsoft.Azure.ServiceBus.RetryPolicy.RunOperation(Func`1 operation, TimeSpan operationTimeout)
   at Microsoft.Azure.ServiceBus.Core.MessageSender.SendAsync(IList`1 messageList)
    public async Task SendAsync(string message)
    {
        var queueMessage = new Message(Encoding.ASCII.GetBytes(message));
        var queueClient = GetQueueClient("myqueue");
        await queueClient.SendAsync(queueMessage);
    }

    public IQueueClient CreateQueueClient(string queueName)
    {
        var messageBusSection = _configuration
            .GetSection("AppSettings:MessageBus");
        var connectionString = messageBusSection["ConnectionString"];
        var path = messageBusSection.GetSection("Queues")[queueName];
        return new QueueClient(connectionString, path);
    }

我认为这不是超出配额的问题,也没有说超时。关于如何调试这个的任何想法?

标签: c#azureservicebus

解决方案


注意:这不一定能解决您的问题(因为错误描述性不是很强)。

使用 ASB 消息传递的最佳实践之一是重用工厂和客户端

建议您发送消息后不要关闭消息工厂或队列、主题和订阅客户端,然后在发送下一条消息时重新创建它们。

您可能只是遇到了某种连接限制,可以通过重用QueueClient而不是在每次发送消息时重新创建它来解决。


推荐阅读