Skip to content

Commit

Permalink
Improved wording of saga documentation article (#164)
Browse files Browse the repository at this point in the history
* better wording for documentation
  • Loading branch information
Guy Baron committed Sep 19, 2019
1 parent f34a647 commit abf9e9d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
9 changes: 5 additions & 4 deletions docs/SAGA.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ When the above is detected grabbit will rollback the bounded transaction and ret

### Configuring a Saga Instance

It is sometimes needed to configure a saga instance with some data before it gets executed.
It is sometimes necessary to configure a saga instance with some data before it gets executed.
grrabit allows you to do so by providing a saga configuration function when registering the saga.
Each time a saga instance gets created or inflated from the persistent store the configuration function will be executed.

Expand All @@ -245,9 +245,10 @@ svc1.RegisterSaga(&BookVacationSaga{}, configSaga)
### Replying to the saga initiator

It is common that during its life cycle a saga will need to report back and send messages with the service that initiated it (sent the command that started the saga).
In the example above when the booking has completed we would like to send a message to the service initiating the booking saga.
The way we have implemented this in the example above is by publishing an event which the initiating service would need to subscribe to and handle to get notified when the booking is complete.
And although this would work it won't be an elegant solution especially if the initiator of the saga is another saga since it means that the initiating saga will need to filter all events and select the single event that correlates to that particular instance.
In the example above when the booking has completed we would like to send a message to the service which initiated the booking saga.
The way we have implemented this in the example above is by publishing an event which the service which initiated the saga would need to subscribe to and handle to get notified when the booking is complete.

Although the above would work it won't be an elegant solution especially if the initiator of the saga is another saga since it means that the initiating saga will need to filter all events and select the single event that correlates to that particular instance.
To relive client code to do so grabbit provides a way for a saga to directly send a message to its initiator, and if the initiator is another saga grabbit will automatically correlate the message with the correct saga instance and invoke the relevant handler.

To send a message to the saga initiator the message handler attached to the saga instance will need to cast the passed in gbus.Invocation argument to a gbus.SagaInvocation and then invoke the ReplyToInitiator function.
Expand Down
1 change: 0 additions & 1 deletion gbus/saga/glue.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ func (imsm *Glue) SagaHandler(invocation gbus.Invocation, message *gbus.BusMessa
newInstance.StartedByRPCID = message.RPCID
newInstance.StartedByMessageID = message.ID

// newInstance.StartedBy =
imsm.Log().
WithFields(logrus.Fields{"saga_def": def.String(), "saga_id": newInstance.ID}).
Info("created new saga")
Expand Down
2 changes: 1 addition & 1 deletion gbus/saga/invocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (si *sagaInvocation) ReplyToInitiator(ctx context.Context, message *gbus.Bu

si.setCorrelationIDs(message, false)

//overridethe correlation ids to those of the message creating the saga
//override the correlation ids to those of the message creating the saga
message.SagaCorrelationID = si.startedBySaga
message.RPCID = si.startedByRPCID
message.CorrelationID = si.startedByMessageID
Expand Down

0 comments on commit abf9e9d

Please sign in to comment.