Skip to content

Commit

Permalink
correlation id in event model
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoomanfr committed May 30, 2022
1 parent a757fa3 commit b0868ab
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ go get github.com/thumperq/[email protected]
1. Define your message(aka event)
```go
type MyEvent struct {
ID string `json:"id,omitempty"`
CorrelationID string `json:"correlationId,omitempty"`
Description string `json:"description,omitempty"`
}

func NewMyEvent(id string, description string) *MyEvent{
func NewMyEvent(correlationId string, description string) *MyEvent{
return &MyEvent{
ID: id,
CorrelationID: correlationId,
Description: description,
}
}
Expand Down Expand Up @@ -50,7 +50,7 @@ bus := thumperq.NewBus(busCfg)
```
4. Publish a message(aka event)
```go
myEvent := NewMyEvent("1234", "Some description!")
myEvent := NewMyEvent("e783a086-7d81-4e4b-bd72-325103735bfa", "Some description!")
err := bus.Publish(ctx, myEvent)
```
5. Subscribe to a message(aka event)
Expand Down Expand Up @@ -85,7 +85,7 @@ func (h *MyHandler) Compensate(msg <-chan handler.HandlerMessage[*MyEvent]) {
busMsg := <-msg
// busMsg.Message -> is type of your event(in this example it's of type *MyEvent)
// busMsg.Headers -> contains contexts' metadata published by the bus if the PropagateContextMetadata in config is set to true
// this is usefule to publish a message to notify other services to compensate the the call. the event id can be used as correlation id to track messages in other services.
// this is usefule to publish a message to notify other services to compensate the the call. the event correlation id can be used as to track messages in other services.
...
}
```
2 changes: 1 addition & 1 deletion pkg/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package handler
const HandleMethodName = "Handle"

type IMessage interface {
Id() string
CorrelationId() string
}

type IHandler[T IMessage] interface {
Expand Down

0 comments on commit b0868ab

Please sign in to comment.