diff --git a/lib/commanded/commands/router.ex b/lib/commanded/commands/router.ex index d726cdb6..494cc3c0 100644 --- a/lib/commanded/commands/router.ex +++ b/lib/commanded/commands/router.ex @@ -524,9 +524,9 @@ defmodule Commanded.Commands.Router do application = Keyword.fetch!(opts, :application) causation_id = Keyword.get(opts, :causation_id) - command_uuid = Keyword.get_lazy(opts, :command_uuid, &UUID.uuid4/0) + command_uuid = Keyword.get_lazy(opts, :command_uuid, &UUID.uuid7/0) consistency = Keyword.fetch!(opts, :consistency) - correlation_id = Keyword.get_lazy(opts, :correlation_id, &UUID.uuid4/0) + correlation_id = Keyword.get_lazy(opts, :correlation_id, &UUID.uuid7/0) metadata = Keyword.fetch!(opts, :metadata) |> validate_metadata() retry_attempts = Keyword.get(opts, :retry_attempts) diff --git a/lib/commanded/event/mapper.ex b/lib/commanded/event/mapper.ex index fc74a0d6..0a43a87c 100644 --- a/lib/commanded/event/mapper.ex +++ b/lib/commanded/event/mapper.ex @@ -37,8 +37,8 @@ defmodule Commanded.Event.Mapper do %ExampleEvent1{}, %ExampleEvent2{} ], - causation_id: Commanded.UUID.uuid4(), - correlation_id: Commanded.UUID.uuid4(), + causation_id: Commanded.UUID.uuid7(), + correlation_id: Commanded.UUID.uuid7(), metadata: %{"user_id" => user_id} ) diff --git a/lib/commanded/event_store/adapters/in_memory.ex b/lib/commanded/event_store/adapters/in_memory.ex index c7fb9611..796e5159 100644 --- a/lib/commanded/event_store/adapters/in_memory.ex +++ b/lib/commanded/event_store/adapters/in_memory.ex @@ -452,7 +452,7 @@ defmodule Commanded.EventStore.Adapters.InMemory do } = event %RecordedEvent{ - event_id: event_id || UUID.uuid4(), + event_id: event_id || UUID.uuid7(), event_number: event_number, stream_id: stream_uuid, stream_version: stream_version, diff --git a/lib/commanded/uuid.ex b/lib/commanded/uuid.ex index 0219a291..88d06d0b 100644 --- a/lib/commanded/uuid.ex +++ b/lib/commanded/uuid.ex @@ -16,4 +16,9 @@ defmodule Commanded.UUID do Generates a UUID using the configured provider (defaults to `Uniq.UUID`). """ defdelegate uuid4, to: @uuid_mod + + @doc """ + Generates a UUIDv7 using the configured provider (defaults to `Uniq.UUID`). + """ + defdelegate uuid7, to: @uuid_mod end