向服务总线主题发送消息花费太多时间

时间:2021-03-19 07:56:29

标签: azure-functions azureservicebus azure-servicebus-topics

我正在从 Azure Functions 向服务总线主题发送消息,当该函数被调用前 3-4 次时,将消息发送到服务总线主题大约需要 10-20 秒,我正在寻找方法减少这个时间,我使用下面的代码向服务总线发送消息。

public class ServiceBusTopicService

    {
    private static ITopicClient _topicClient;

    public ServiceBusTopicService(string serviceBusConnectionString, string topicName)
    {
        _topicClient = new TopicClient(serviceBusConnectionString, topicName);
    }
    private  static async Task SendMessage(string json)
    {
        var message = new Message(Encoding.UTF8.GetBytes(json));

        await _topicClient.SendAsync(message);
    }

    public async Task BroadCastEvent(string matasId, Guid correlationId, string profileSource, string eventType)
    {
        var eventToPost = JsonConvert.SerializeObject(ProfileEvent.GetProfileEvent(matasId, correlationId, profileSource, eventType));
        await SendMessage(eventToPost);
    }
}

1 个答案:

答案 0 :(得分:0)

如果只是在启动时,那么很可能是 cold start problem

有关解决方案,请参阅 this answer