大众运输推迟响应萨加斯 [英] masstransit deferred respond in sagas

查看:85
本文介绍了大众运输推迟响应萨加斯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究在公共交通中使用sagas来协调多个服务中的活动.传奇的寿命很短-如果一切顺利的话,不到2秒.

I am investigating using sagas in mass transit to orchestrate activities across several services. The lifetime of the saga is short - less than 2 seconds if all goes well.

对于我的用例,我想使用请求/响应方法,即客户端请求一个命令,由传奇来处理该命令,在接收到消息时经历一些状态更改,并最终响应所发起的第一个命令传奇,此时客户端会收到响应并显示传奇的结果.

For my use case, i would like to use the request/respond approach, whereby the client requests a command, the saga handles that command, goes through some state changes as messages are received and eventually responds to the first command that initiated the saga, at which point the client receives the response and can display the result of the saga.

据我所知,此时,上下文不再知道初始请求.如何回复以这种方式收到的消息?在处理第一个事件时,我是否可以保留传奇数据,并在以后用于回复?

From what i can see, by this point, the context is no longer aware of the initial request. How can I reply to a message that was received in this way? Is there something i can persist to the saga data when handling the first event, and use that to reply later on?

推荐答案

感谢Alexey.我已经意识到我可以将原始消息中的ResponseAddress和RequestId存储在传奇中,然后再构造一个Send().

Thanks Alexey. I have realised that I can store the ResponseAddress and RequestId from the original message on the saga, and then construct a Send() later on.

从原始请求中获取响应详细信息

Getting the response details from the original request

MassTransit.EntityFrameworkIntegration.Saga.EntityFramework

    SagaConsumeContext<TSagaData, TMessage> payload;
    if (ctx.TryGetPayload(out payload))
    {                
       ResponseAddress = payload.ResponseAddress;
       RequestId = payload.RequestId ;                          
    }

发送回复

var responseEndpoint = await ctx.GetSendEndpoint(responseAddress);
await responseEndpoint.Send(message, c => c.RequestId = requestId);

这篇关于大众运输推迟响应萨加斯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆