Skip to content

fabriziosestito/commanded-spear-adapter

Repository files navigation

CI Hex.pm Hex Docs

Spear EventStoreDB adapter for Commanded

Commanded EvenstoreDB adapter based on spear. The code is based on commanded-extreme-adapter.


Hex package

Changelog


Getting started

The package can be installed from hex as follows.

  1. Add commanded_spear_adapter to your list of dependencies in mix.exs:

    def deps do
      [{:commanded_spear_adapter, "~> 0.2"}]
    end
  2. Define and configure your Commanded application:

    defmodule MyApp.Application do
      use Commanded.Application, otp_app: :my_app
    end
  3. Configure the Commanded application to use the Commanded.EventStore.Adapters.Spear adapter and set the connection settings for the Event Store you are using:

    # config/config.exs
    config :my_app, MyApp.Application,
      event_store: [
        adapter: Commanded.EventStore.Adapters.Spear,
        serializer: Commanded.Serialization.JsonSerializer,
        stream_prefix: "myapp",
        spear: [
          connection_string: "esdb://localhost:2113"
        ]
      ]

    Refer to the Spear library documentation for details on the available connection settings.

    Note: Stream prefix must not contain a dash character ("-").

Partition

This adapter does not support partitioning via the partition_by option.

Multi-node setup

commanded_spear_adapter uses Erlang's :global registry to prevent duplicate subscriptions by stream/name.

Use a serializer other than JSON

To serialize and deserialize events in formats other than JSON, you must specify the content-type of the event body.

# config/config.exs
config :my_app, MyApp.Application,
  event_store: [
    adapter: Commanded.EventStore.Adapters.Spear,
    serializer: MyApp.MessagePackSerializer,
    content_type: "application/x-msgpack"
    ...
  ]

The content_type settings defaults to application/json.

Running the Event Store

You must run the Event Store with all projections enabled and standard projections started.

Use the --run-projections=all --start-standard-projections=true flags when running the Event Store executable.

Credits