Giter VIP home page Giter VIP logo

docs's Introduction

home heroImage description actionText actionLink features footer
true
/eventide-icon-132.png
Pub/Sub, Event Sourcing, Evented Microservices
Get Started →
/examples/quickstart.md
title details
Pub/Sub
Pub/Sub services based on persistent event streams with support for event sourcing, parallelization, and a hosting runtime
title details
Microservices
Message-based services hosted in any number of operating system processes or machines, with actor-based pub-sub consumers, consumer groups, message dispatching, and handlers
title details
Event Sourcing
Business logic entities projected from event streams with caching and snapshotting
MIT Licensed | Copyright © 2015-present The Eventide Project

A Brief Example...

# Account command handler with withdrawal implementation
# Business logic for processing a withdrawal
class Handler
  include Messaging::Handle

  handle Withdraw do |withdraw|
    account_id = withdraw.account_id

    account = store.fetch(account_id)

    unless account.sufficient_funds?(withdraw.amount)
      logger.info('Withdrawal rejected')
      return
    end

    withdrawn = Withdrawn.follow(withdraw)

    time = clock.iso8601
    withdrawn.processed_time = time

    stream_name = stream_name(account_id)

    write.(withdrawn, stream_name)
  end
end

# Withdraw command message
# Send to the account component to effect a withdrawal
class Withdraw
  include Messaging::Message

  attribute :account_id, String
  attribute :amount, Numeric
  attribute :time, String
end

# Withdrawn event message
# Event is written by the handler when a withdrawal is successfully processed
class Withdrawn
  include Messaging::Message

  attribute :account_id, String
  attribute :amount, Numeric
  attribute :time, String
  attribute :processed_time, String
end

# Account entity
# The account component's model object
class Account
  include Schema::DataStructure

  attribute :id, String
  attribute :balance, Numeric, default: 0

  def withdraw(amount)
    self.balance -= amount
  end

  def sufficient_funds?(amount)
    balance >= amount
  end
end

# Account entity projection
# Applies account events to an account entity
class Projection
  include EntityProjection

  entity_name :account

  apply Withdrawn do |withdrawn|
    account.id = withdrawn.account_id

    amount = withdrawn.amount

    account.withdraw(amount)
  end
end

# Account entity store
# Projects an account entity and keeps a cache of the result
class Store
  include EntityStore

  entity Account
  projection Projection
end

This code is not a complete implementation and not production-ready. It's intended only to provide a very high-level introductory overview.

docs's People

Contributors

sbellware avatar ntl avatar ashleymichal avatar whoward avatar aaronjensen avatar bradrobertson avatar juanpaco avatar gringocl avatar stevenharman avatar ahmgeek avatar brennovich avatar alexandru-calinoiu avatar jamezilla avatar mjq avatar michaelsmanley avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.