Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing Context in CQRS #206

Closed
jpearll opened this issue Nov 10, 2020 · 1 comment
Closed

Passing Context in CQRS #206

jpearll opened this issue Nov 10, 2020 · 1 comment

Comments

@jpearll
Copy link

jpearll commented Nov 10, 2020

Hi,

I am trying to pass a context from an Event Handler (following CQRS archetype), to another message handler, but it is not working.

From a Command Handler

func (h Handler) Handle(ctx context.Context, c interface{}) error {
   // ...
   ctx = context.WithValue(ctx, Key, MyStruct{Field: "test"})
  return h.eventBus.Publish(ctx, &event.UserCreated{})
}

To an Event Handler

func (h Handler) Handle(ctx context.Context, c interface{}) error {
   // value here is nil
   value  := ctx.Value(Key)
}

What is the way to propagate Context across Command & Event Handlers ?

@roblaszczak
Copy link
Member

Hello @jpearll, you should not use context but message metadata instead.

Context is not propagated by any Pub/Sub (it could be possible only with Go Channel Pub/Sub, but it's not possible currently, it's connected with this PR and discussion #205).

Anyway, it's not possible by design, and message metadata was designed to propagate any data that you don't want to send via payload.

I hope it made it clear and I'm closing the issue. If it's not clear, please let me know :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants