Spear EventStoreDB adapter for Commanded
Commanded EvenstoreDB adapter based on spear. The code is based on commanded-extreme-adapter.
Getting started
The package can be installed from hex as follows.
Add
commanded_spear_adapterto your list of dependencies inmix.exs:def deps do[{:commanded_spear_adapter, "~> 0.1"}]endDefine and configure your Commanded application:
defmodule MyApp.Application douse Commanded.Application, otp_app: :my_appendConfigure the Commanded application to use the
Commanded.EventStore.Adapters.Spearadapter and set the connection settings for the Event Store you are using:# config/config.exsconfig :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 ("-").
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
- Ben Smith for commanded and commanded-extreme-adapter
- Michael Davis for spear
- Fabrizio Sestito hacking on this during SUSE/openSUSE Hack Week 21