我正在开发一个使用 NServiceBus ESB 的项目。微服务“A”向微服务“B”发送请求,请求存储在数据库中的数据记录列表(例如讲师记录)。 有没有办法在 Handle 方法中我们可以做一些类似的事情:
List<Instructor> instructors = await _coursecontext.CourseSet
.Where(x => x.InstructorGuid == instructor.Instructor_Unique_Id)
.ToListAsync();
目前我收到错误消息,必须将 Handle 方法设为异步。
谢谢!
我将 Handle 更改为异步,但随后遇到了 Handle 未正确实现的问题。
NServiceBus 处理程序 支持基于任务的异步,只需在实现中添加
async
关键字(可以使用 await
)即可:
public class MyAsyncHandler :
IHandleMessages<MyMessage>
{
public async Task Handle(MyMessage message, IMessageHandlerContext context)
{
// do something with the message data
}
}
另请参阅: