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

Include application and handler_name as additional event handler and upcaster metadata #396

Merged
merged 2 commits into from Aug 9, 2020

Conversation

slashdotdash
Copy link
Member

Include the associated Commanded Application and event handler name as additional system provided metadata key/values. This allows event handlers to determine the current application and handler name when started with these options configured at runtime.

Example

defmodule ExampleEventHandler do
  use Commanded.Event.Handler
  
  @impl Commanded.Event.Handler
  def handle(event, metadata) do
    application = Keyword.fetch!(metadata, :application)
    handler_name = Keyword.fetch!(metadata, :handler_name)

    :ok
  end
end

Usage:

{:ok, _pid} = ExampleEventHandler.start_link(application: MyApp, name: "ExampleEventHandler1")
{:ok, _pid} = ExampleEventHandler.start_link(application: MyApp, name: "ExampleEventHandler2")

The above demonstrates using the same event handler module but configured at runtime with a unique name so that two event store subscriptions are created and both handlers receive events.

…metadata

Include the associated Commanded Application and event handler name as additional system provided metadata key/values.
@slashdotdash slashdotdash merged commit 638c3b6 into master Aug 9, 2020
@slashdotdash slashdotdash deleted the feature/event-handler-metadata branch August 9, 2020 23:10
@slashdotdash slashdotdash changed the title Include application and handler_name as additional event handler metadata Include application and handler_name as additional event handler and upcaster metadata Aug 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant