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

24 views
Skip to first unread message

Doug Paice

unread,
Jun 22, 2017, 5:53:10 AM6/22/17
to 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

unread,
Jun 22, 2017, 12:59:21 PM6/22/17
to 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

unread,
Jun 22, 2017, 10:07:04 PM6/22/17
to 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.
Reply all
Reply to author
Forward
0 new messages