Skip to content

Instantly share code, notes, and snippets.

Ben Smith slashdotdash

Block or report user

Report or block slashdotdash

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
slashdotdash /
Created Sep 11, 2019
Commanded event handler default error handling

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.


defmodule MyApp.ExampleHandler do
  use Commanded.Event.Handler, name: __MODULE__
  use Commanded.Event.DefaultErrorHandling, retries: 3
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
slashdotdash / event_telemetry.ex
Created May 3, 2019
A Commanded event handler to produce `:telemetry` events for each recorded event.
View event_telemetry.ex
defmodule Commanded.EventTelemetry do
@moduledoc """
A Commanded event handler to produce `:telemetry` events for each recorded
It produces the following event:
- `[:commanded, :event, :published]`
slashdotdash / telemetry.ex
Last active May 3, 2019
A Commanded middleware to instrument the command dispatch pipeline with `:telemetry` events.
View telemetry.ex
defmodule Commanded.Middleware.Telemetry do
@moduledoc """
A Commanded middleware to instrument the command dispatch pipeline with
`:telemetry` events.
It produces the following three events:
- `[:commanded, :command, :dispatch, :start]`
- `[:commanded, :command, :dispatch, :success]`
- `[:commanded, :command, :dispatch, :failure]`
slashdotdash /
Created Mar 26, 2019
Architecture principles from "Design It!" by Michael Keeling

Architecture principles

From Design It! From Programmer to Software Architect by Michael Keeling.

  • Partition system and assign responsibilities.
  • Decide trade-offs among quality attributes:
    • Performance (response time)
    • Scalability (annual growth)
    • Availability
    • Security
slashdotdash / aggregate_case.ex
Last active Aug 8, 2019
Commanded aggregate ExUnit case template
View aggregate_case.ex
defmodule AggregateCase do
@moduledoc """
Defines a test case to be used by aggregate tests.
use ExUnit.CaseTemplate
alias Commanded.Aggregate.Multi
using opts do
slashdotdash / jsonb_serializer.ex
Last active Aug 16, 2019
Commanded jsonb serializer with decode support
View jsonb_serializer.ex
defmodule JsonbSerializer do
@moduledoc """
Serialize to/from PostgreSQL's native `jsonb` format.
@behaviour EventStore.Serializer
alias Commanded.EventStore.TypeProvider
alias Commanded.Serialization.JsonDecoder
slashdotdash /
Last active Mar 13, 2019
Commanded middleware to enrich commands during dispatch, such as calling an external API.

Commanded middleware for command enrichment


Add the EnrichCommand middleware to your command router:

defmodule MyApp.Router do
  use Commanded.Commands.Router
slashdotdash / assertions.ex
Created Dec 6, 2018
Commanded event store assertion tp refute receive event
View assertions.ex
defmodule Commanded.EventStore.Assertions do
import ExUnit.Assertions
alias Commanded.EventStore.RecordedEvent
@doc """
Refute that an event of the given type has been received.
An optional predicate may be provided to filter events matching the refuted
View data_case.ex
defmodule MyApp.DataCase do
use ExUnit.CaseTemplate
using do
quote do
import Commanded.Assertions.EventAssertions
setup do
You can’t perform that action at this time.