Comments (5)
@sunny-g You could use the existing in-memory adapter as a basis for an mnesia event store. That should give you an foundation to build on.
The behaviour you need to implement is given below:
defmodule Commanded.EventStore do
@type stream_uuid :: String.t
@type start_from :: :origin | :current | integer
@type stream_version :: integer
@type subscription_name :: String.t
@type source_uuid :: String.t
@type snapshot :: SnapshotData.t
@type reason :: term
@doc """
Append one or more events to a stream atomically.
"""
@callback append_to_stream(stream_uuid, expected_version :: non_neg_integer, events :: list(EventData.t)) :: {:ok, stream_version} | {:error, reason}
@doc """
Streams events from the given stream, in the order in which they were originally written.
"""
@callback stream_forward(stream_uuid, start_version :: non_neg_integer, read_batch_size :: non_neg_integer) :: Enumerable.t | {:error, :stream_not_found} | {:error, reason}
@doc """
Subscriber will be notified of every event persisted to any stream.
"""
@callback subscribe_to_all_streams(subscription_name, subscriber :: pid, start_from) :: {:ok, subscription :: pid}
| {:error, :subscription_already_exists}
| {:error, reason}
@doc """
Acknowledge receipt and successful processing of the given event received from a subscription to an event stream.
"""
@callback ack_event(pid, RecordedEvent.t) :: any
@doc """
Unsubscribe an existing subscriber from all event notifications.
"""
@callback unsubscribe_from_all_streams(subscription_name) :: :ok
@doc """
Read a snapshot, if available, for a given source.
"""
@callback read_snapshot(source_uuid) :: {:ok, snapshot} | {:error, :snapshot_not_found}
@doc """
Record a snapshot of the data and metadata for a given source
"""
@callback record_snapshot(snapshot) :: :ok | {:error, reason}
@doc """
Delete a previously recorded snapshop for a given source
"""
@callback delete_snapshot(source_uuid) :: :ok | {:error, reason}
end
from commanded.
@sunny-g There are a number of event store adapter tests included in Commanded that you can use to verify your mnesia event store, if you decide to build one.
- Configure Commanded as a dependency (no runtime) in
mix.exs
:
defp deps do
[
{:commanded, "~> 0.10", runtime: false},
]
end
- Fetch & compile deps:
$ mix do deps.get, deps.compile
- Create a test file and include the event store adapter test files from Commanded:
# test/event_store_adapter_test.exs
# execute event store adapter tests from Commanded
Code.require_file "../deps/commanded/test/event_store_adapter/append_events_test.exs", __DIR__
Code.require_file "../deps/commanded/test/event_store_adapter/snapshot_test.exs", __DIR__
Code.require_file "../deps/commanded/test/event_store_adapter/subscription_test.exs", __DIR__
- Configure the event store adapter in
test_helper.exs
:
# test/test_helper.exs
ExUnit.start()
# configure this event store adapter for Commanded
Application.put_env(:commanded, :event_store_adapter, Commanded.EventStore.Adapters.Mnesia)
Application.put_env(:commanded, :reset_storage, fn ->
# ... reset mnesia
end)
- Run the tests:
$ mix test
This approach is used by both the existing adapters: commanded-eventstore-adapter and commanded-extreme-adapter.
from commanded.
Mnesia is fun, but boy does it take a lot of time away from your life haha.
from commanded.
@slashdotdash that's what I thought, thanks!
from commanded.
@slashdotdash fantastic, thanks for this, I'll share the link here when I get around to it.
from commanded.
Related Issues (20)
- Wiki Testing section is outdated HOT 1
- warning: redefining module Commanded.Serialization.JsonDecoder.Any HOT 2
- Event number gaplessness required?
- Commanded.aggregate_state does not work when aggregate identity has a prefix HOT 10
- Process manager router option not working
- Lessons learned from performance optimization - an unlikely culprit HOT 3
- no function clause matching in Commanded.Commands.Dispatcher.telemetry_stop/3 HOT 1
- Docs questions
- Stacktrace in event handler error? HOT 2
- Paralelization Strategies in EventHandlers
- Should Commanded.Event.Handler support messages from swarm? HOT 2
- Event retention policies?
- please support multiple commanded application with one eventstore HOT 6
- Process Manager state serialization breaks when using a custom TypeProvider with the JsonSerializer
- `Commanded.ProcessManagers.ProcessManager.identity/0` function returns `nil` in unit tests
- no function clause matching in Commanded.Event.Handler.partition_event/4 HOT 1
- EventstoreDB is sunsetting the TCP protocol HOT 1
- Is it a bad practice for an event handler to depend on a projector completion? HOT 2
- Snapshotting 2 Aggregates having same identity
- Is it possible to log contents of InMemoryEventStore on failed test?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from commanded.