Accessing initial saga state or detecting state changes or passing extra data with the

瀏覽次數:24 次
跳到第一則未讀訊息

Doug Paice

未讀,
2017年6月22日 清晨5:53:102017/6/22
收件者:masstransit-discuss
I've got a use case where if certain values of a saga change then I need to publish a message (send a command to a handler to call an external system)

The simplest (to me) option is:
  1. on the way in map the initial state to the out-going message type
  2. perform the update
  3. map to the final state to the out-going message type
  4. if they are different then publish the message
I was hoping do do something like:

During(Running)
.When(Updated)
.Then(context => MapToOutGoingMessage(context.Instance)) // save to initial
.Then(MutateState)
.Then(context => MapToOutGoingMessage(context.Instance)) // save to final
.If(context => context.??.initial != context.??.final,
binder => binder.Publish(context => context.??.final))
 
But there seems to be no simple way of passing data between the steps, unless GetOrAddPayload is the way

Thanks

Chris Patterson

未讀,
2017年6月22日 中午12:59:212017/6/22
收件者:masstrans...@googlegroups.com
GetOrAddPayload() is the way to pass context/data between steps, so that's your best option. I'd make a class that has the behavior in it to compare the outgoing message instances and determine if it needs to be published. Then you can use it in the If statement...

.If(context => context.GetPayload<IOutgoingMessageBuilder>().IsUpdated, x => x.Publish(context => context.GetPayload<IOutgoingMessageBuilder>().OutgoingMessage));

Or something to that nature.


--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.
To post to this group, send email to masstransit-discuss@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/masstransit-discuss/7d1b55e8-92f4-4f52-9d9a-7b09ab10a554%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Doug Paice

未讀,
2017年6月22日 晚上10:07:042017/6/22
收件者:masstransit-discuss
Great, thanks


On Friday, June 23, 2017 at 12:59:21 AM UTC+8, Chris Patterson wrote:
GetOrAddPayload() is the way to pass context/data between steps, so that's your best option. I'd make a class that has the behavior in it to compare the outgoing message instances and determine if it needs to be published. Then you can use it in the If statement...

.If(context => context.GetPayload<IOutgoingMessageBuilder>().IsUpdated, x => x.Publish(context => context.GetPayload<IOutgoingMessageBuilder>().OutgoingMessage));

Or something to that nature.

On Thu, Jun 22, 2017 at 2:53 AM, Doug Paice <doug....@baralong.org> wrote:
I've got a use case where if certain values of a saga change then I need to publish a message (send a command to a handler to call an external system)

The simplest (to me) option is:
  1. on the way in map the initial state to the out-going message type
  2. perform the update
  3. map to the final state to the out-going message type
  4. if they are different then publish the message
I was hoping do do something like:

During(Running)
.When(Updated)
.Then(context => MapToOutGoingMessage(context.Instance)) // save to initial
.Then(MutateState)
.Then(context => MapToOutGoingMessage(context.Instance)) // save to final
.If(context => context.??.initial != context.??.final,
binder => binder.Publish(context => context.??.final))
 
But there seems to be no simple way of passing data between the steps, unless GetOrAddPayload is the way

Thanks

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.
To post to this group, send email to masstrans...@googlegroups.com.
回覆所有人
回覆作者
轉寄
0 則新訊息