我有以下课程:
public abstract class ServiceBusQueueService : IServiceBusQueueService
{
private readonly string _sbConnect;
protected ServiceBusQueueService(string sbConnect)
{
_sbConnect = sbConnect;
}
public async Task EnqueueMessage(IntegrationEvent message)
{
var topicClient = new TopicClient(_sbConnect, message.Topic, RetryPolicy.Default);
await topicClient.SendAsync(message.ToServiceBusMessage());
}
}
Run Code Online (Sandbox Code Playgroud)
正在使用的是这样的:
public ulong CreateBooking()
{
// Other code omitted for brevity
ulong bookingId = 12345; // Pretend this id is generated sequentially on each call
_bookingServiceBusQueueService.EnqueueMessage(new BookingCreatedIntegrationEvent
{
BookingId = bookingId
}).GetAwaiter().GetResult();
return bookingId;
}
Run Code Online (Sandbox Code Playgroud)
当EnqueueMessage从我的CreateBooking方法调用该方法时,该程序挂起并且在点击该行之后不再继续await topicClient.SendAsync(message.ToServiceBusMessage());
现在代码工作,当我将调用更改为my …