Skip to content

Instantly share code, notes, and snippets.

Avatar

Ben Smith slashdotdash

View GitHub Profile
View category_stream_linker.ex
defmodule EventStore.CategoryStreamLinker do
@moduledoc """
Links streams from aggregate instances to their respective category streams.
example: events from stream_uuid of `contractors_contract-07c52787-da0c-444f-9783-5d380f7093f9` will be
linked to stream_uuid of `contractors_contract`.
"""
use Commanded.Event.Handler,
application: My.App,
View invalid_event.ex
defmodule InvalidEvent do
@doc """
Module to be used when an event cannot be deserialized from the event store.
The payload field will be populated with the source event data if
deserialization is possible.
Receiving this event usually indicates an event has been removed or renamed in
the source code between releases. Deserializing to this invalid event module
allows the application to continue running, otherwise it would terminate as
View event_store_expectations.md

Expectations

What I expect from some system managing storage of streams of events, intended to be used in an event-sourced system.

  • ability to create streams
  • ability to delete streams
  • ability to use optimistic locking on stream level
  • ability to write a batch of events in one stream atomically and durably
  • ability to read events from one stream
  • ability to read all events in the store ( the so called "$all" stream)
@slashdotdash
slashdotdash / default_behaviour.ex
Created Sep 8, 2020 — forked from christhekeele/default_behaviour.ex
Behaviours with Defaults for Elixir
View default_behaviour.ex
defmodule Default.Behaviour do
@moduledoc """
Creates a behaviour that carries its own default implementation.
When used into a behaviour module, when that module in turn is used, all functions
defined on it are given to the using module.
This allows you to have concrete implementations of the behaviour's default functionality
for testing, unlike cramming them all into a __using__ macro.
@slashdotdash
slashdotdash / README.md
Created May 28, 2020
Elixir GenServer with a `handle_info/2` callback will crash when receiving an unexpected message
View README.md

Elixir GenServer with a handle_info/2 callback will crash when receiving an unexpected message

Define a GenServer with a handle_info callback function:

defmodule Echo do
  use GenServer

  def start_link(reply_to) do
    GenServer.start_link(__MODULE__, reply_to)
@slashdotdash
slashdotdash / json_serializer.ex
Created Feb 21, 2020
Commanded JSON serializer supporting string keys
View json_serializer.ex
defmodule JsonSerializer do
alias Commanded.EventStore.TypeProvider
alias Commanded.Serialization.JsonDecoder
@doc """
Serialize given term to JSON binary data.
"""
def serialize(term) do
Jason.encode!(term)
end
@slashdotdash
slashdotdash / README.md
Created Feb 18, 2020
Publish to an Absinthe GraphQL subscription
View README.md
@slashdotdash
slashdotdash / open_account.ex
Last active Dec 30, 2019
Use Ecto Changeset to validate a command
View open_account.ex
defmodule OpenAccount do
defstruct [:account_number, :initial_balance]
@types %{
account_number: :string,
initial_balance: :integer
}
def validate(params) do
{params, @types}
@slashdotdash
slashdotdash / README.md
Created Sep 11, 2019
Commanded event handler default error handling
View README.md

Commanded event handler default error handling

Implement a default event handler error/3 callback function with optional support for retrying failed events before eventually skipping it.

Usage

defmodule MyApp.ExampleHandler do
  use Commanded.Event.Handler, name: __MODULE__
  use Commanded.Event.DefaultErrorHandling, retries: 3
@slashdotdash
slashdotdash / CloudWatchReporter.ex
Last active Jul 8, 2019
AWS CloudWatch reporter for Commanded telemetry.
View CloudWatchReporter.ex
defmodule CloudWatchReporter do
use GenServer
require Logger
alias ExAws.Cloudwatch
@namespace "My/App"
def start_link(args) do