Skip to content

Instantly share code, notes, and snippets.

View dasch's full-sized avatar
💭
LOOKING INTENTLY INTO THE VOID

Daniel Schierbeck dasch

💭
LOOKING INTENTLY INTO THE VOID
View GitHub Profile
module EventLog
AVRO = AvroTurf.new(schemas_path: "app/schemas/")
def self.publish(event_name, payload = {})
data = AVRO.encode(payload, schema_name: event_name)
DeliveryBoy.deliver(data, topic: event_name)
end
end
# app/controllers/posts_controller.rb
class PostsController < ApplicationController
def show
@post = Post.find(params[:id])
event = {
post_id: @post.id,
ip_address: request.remote_ip,
timestamp: Time.now,
}
@dasch
dasch / README.md
Last active July 7, 2017 12:38
Event Sourcing Example

The rules of the reservation of a train are the following:

  • We cannot reserve seats in a train if it bumps up the occupancy over 70%
  • All the reserved seats should be in the same coach (we cannot separate families)
  • Preferably, we should avoid bumping the occupancy of a coach over 80%
class Consumer
class Fetcher
def initialize(input, output)
@input, @output = input, output
@running = true
end
def run
while @running
using System;
using System.Web;
using System.Web.Mvc;
using System.Diagnostics;
/// <summary>
/// A simple attribute that times controller actions, returning the measured time
/// in the HTTP header "X-Duration".
/// </summary>
@dasch
dasch / Kafka.elm
Last active January 29, 2017 03:30
module Kafka exposing (..)
import Stream exposing (Source, Sink)
source : String -> Source String String
sink : String -> Sink String String
class IoFuture
def initialize(io, &block)
@io, @block = io, block
end
def to_io
@io
end
def value
module Aggregate exposing (..)
type alias Aggregate cmd error event state =
{ init : state
, apply : event -> state -> state
, handle : cmd -> state -> Result error event
}
type alias Coder cmd event =
{ decodeEvent : String -> Result String event
module SearchQueryIndexer exposing (main)
import Stream exposing (Stream, Pipeline)
main : Pipeline
main =
Stream.readFrom "searches"
|> Stream.filter (\search -> search.resultCount > 0)
module Kafka.Consumer where
import Kafka
type alias Config =
{ groupId : String
, checkpointInterval : Maybe Int
, checkpointThreshold : Maybe Int
, heartbeatInterval : Int
}