我正在从 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);
}
}