0.0
No commit activity in last 3 years
No release in over 3 years
An opinionated read model framework for use with EventStore
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 3.7

Runtime

~> 0.13
~> 3.5
~> 2.1
~> 2.0
 Project Readme

EsReadModel

An opinionated read model framework for EventStore.

Your reducer can be anything that responds to #call. It will receive two arguments -- the current state and the event. The current state will be nil if no events have been processed yet. The reducer function must return the new state.

Routes

At the moment every route handler must return a Hash. (If you don't, the Api module will crash!)

Example usage

require 'rack/cors'
require 'es_readmodel'
require_relative './active_users'
require_relative './list_users'
require_relative './get_user_details'

ENV['RACK_ENV'] = 'none'
ENV['readmodel.name'] = 'users'

use Rack::Cors do
  allow do
    origins '*'
    resource '*', headers: :any, methods: :any, max_age: 0
  end
end

use EsReadModel::RackSubscriber,
  es_url:      'http://localhost:2113',
  es_username: ENV['ES_USERNAME'],
  es_password: ENV['ES_PASSWORD'],
  reducer:     ActiveUsers.new,
  listener:    EsReadModel::Logger.new

run EsReadModel::Api.new(
  '/users'          => ListUsers.new,
  '/users/:user_id' => GetUserDetails.new
)