我觉得我已经接近完成这项工作,但似乎无法完成...
我有一个带有传奇/状态机的 .NET Core ASP 应用程序,它在大多数情况下似乎运行良好。它:
- 收到请求
- 发布由传送单选取的事件
- 当传送单完成时,它会发布一个事件
- 事件拾起saga
- 然后 saga 向请求/响应消费者发送一个请求
- 回应回到传奇
- 但是然后我使用 RespondAsync 尝试将响应发送回原始调用控制器,但是没有任何东西可以返回
我的控制器看起来像:
private readonly IRequestClient<IRequestLink, IRequestLinkCompleted> _client;
public async Task<IActionResult> CreateLinkAsync([FromBody]CreateLinkRequest request)
{
var requestLink = new RequestLink {
GroupName = $"{request.Name} Group",
Name = request.Name,
LinkId = Guid.NewGuid()
};
var result = await _client.Request(requestLink).ConfigureAwait(false);
return Ok();
}
我的传奇故事的精简版如下所示:
Request(() => LinkRequest, x => x.RequestId, cfg =>
{
cfg.ServiceAddress = new Uri($"rabbitmq://localhost/request_end_point_name");
cfg.SchedulingServiceAddress = new Uri($"rabbitmq://localhost/request_end_point_name");
cfg.Timeout = TimeSpan.FromSeconds(30);
});
During(RequestReceived,
When(LinkCreatedEvent)
.Request(LinkRequest, context => new SelectUrlByPublicId(context.Data.DatabaseId, context.Data.LinkId))
.TransitionTo(LinkRequest.Pending));
During(LinkRequest.Pending,
When(LinkRequest.Completed)
.ThenAsync(context => context.RespondAsync(new RequestLinkCompleted
{
CorrelationId = LinkRequest.GetRequestId(context.Instance),
DatabaseId = context.Data.DatabaseId
}))
.Finalize());
最后在我的启动代码中,我将请求/响应配置为:
services.AddScoped<IRequestClient<IRequestLink, IRequestLinkCompleted>>(x => new MessageRequestClient<IRequestLink, IRequestLinkCompleted>(_bus, new Uri($"{messageBusSettings.Host}/create_link_saga"), TimeSpan.FromSeconds(30)));
我猜 RespondAsync 调用没有使用正确/原始的 requestId,但我不知道如何检查或更改它。谁能帮忙?