Closed yordis closed 1 year ago
Yeah the custom_metadata
field should be used for this: any extra keys in metadata
are ignored when writing a %Spear.Event{}
. For example:
correlation_id = Spear.Event.uuid_v4()
Spear.Event.new("hello", %{}, custom_metadata: Jason.encode!(%{"$correlationId" => correlation_id, "$causationId" => Spear.Event.uuid_v4()}))
|> List.wrap()
|> Spear.append(conn, "mystreamname")
If the builtin $by_correlation_id
projection is running it should create a new $bc-${correlation_id}
stream for that event.
Reading: https://developers.eventstore.com/server/v21.10/streams.html#event-metadata
How do I pass
$correlationId
or$causationId
to the events?I am not sure if I suppose to pass it as part of
custome_metadata
or if I suppose to update themetadata
key under theSpear.Event
struct based on the following code snippet: https://github.com/NFIBrokerage/spear/blob/40d5f2f12eae2090e90d0d5e5cddf50329ff1222/lib/spear/event.ex#L162-L165I appreciate any help you can provide.