0

I am sending messages to Service Bus Topic from Azure Functions, and when the function is called for the first 3-4 times, it takes around 10-20 seconds to send message to Service Bus Topic, and I am looking ways to reduce this time, I am sending message to service bus using below code.

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);
    }
}
Shabir jan
  • 2,295
  • 2
  • 23
  • 37

1 Answers1

0

If it's only at start up then it's very likely cold start problem.

See this answer for solutions.

Kashyap
  • 15,354
  • 13
  • 64
  • 103
  • thanks for your answer, I have checked the other dependencies in the same instance of Azure Function, took less than 100ms but only Service bus took 20 seconds. So i think it's more related to Service Bus latency issue. – Shabir jan Mar 20 '21 at 10:04