0.03
Repository is archived
No commit activity in last 3 years
No release in over 3 years
There's a lot of open issues
Rails Disco internals: rake tasks, generators and the commandline interface
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

< 4.2.0, > 3.2.0
 Project Readme

Build Status Coverage Status Dependency Status Code Climate Gem Version License

Rails Disco Logo

Rails Disco - A distributed party with commands, events and projections

Rails Disco is based on Ruby on Rails and makes event sourcing easy. Greg Young showed the advantages of event sourcing multiple times. GOTO Conference Talk (Chicago 2014)

Rails Disco consists out of three main parts: commands, events and projections.

Commands will be created and executed by actions of your controller, instead of directly manipulating your model. These commands are only the order to do something and after possible validations, the framework executes them by creating an event and finally manipulating the model.

The events will be all stored in a separate database and also published to all projections, where they can be processed to update the projections model/database

Finally projections are your representation of your data, they get the events and process them, to get the needed information for building up their models.

Requirements

  • At the moment Rails Disco uses Rails 4. Maybe it works with Rails 3.2, but we didn't test that.

  • Because Rails Disco relies on bunny for sending the events from the domain to the projection, you need RabbitMQ on your system.

  • Any Server which is capable of streaming, e.g. puma or thin (standard Rails server WEBrick will not work). If you are facing problems installing puma on Windows, here is a tutorial.

Getting Started

  1. Install Rails Disco at the command prompt

     gem install rails-disco
    
  2. At the command prompt, create a new Rails Disco application.

     disco new myapp
    

    where myapp is the name of you application.

    (Note: You can also add Rails Disco to an existing Rails application. Simply omit the application name and run the command inside your application.)

  3. Change directory to myapp and migrate the databases:

     cd myapp
     rake disco:migrate:setup
    

    This will operate on the Rails (= projection) and the domain database. You can configure the domain database and more Rails Disco related configurations in config/disco.yml.

  4. If you just want to look a some standard server output, start the disco server (Remember to use a server which is capable of streaming, which means not WEBrick). Else go ahead and skip this point.

     disco server
    

    This will start the domain, the projection and the web server, but you won't see much of the disco yet.

  5. For a humble start, let's create the scaffold for a simple blog system:

     disco generate scaffold Post title:string text:text
    

    The syntax is leaned to Rails' generate style and it basically creates a resource Post with a title and a text attribute.

  6. Now that we have something to rely on, lets migrate and see it in action:

     rake disco:migrate
     disco server
    
  7. Go to http://localhost:3000/posts and you'll see an empty list of our posts with a link to create a new one. Go ahead and create one. If you watch the console output, you can see that an event is created, published and processed by a projection.

  8. If you look at your databases, you see in both of them a table posts, which contains your freshly created post. The domain database also contains a table domain_events. There you find an event for your post creation. Lets see this in action.

  9. Clear your projection database and restart the server.

     rake disco:db:drop
     rake disco:migrate
     disco server
    

    You will see some console output, the projection requests the missing posts from the domain. Finally the state of your projection database will be restored.

  10. That's it for now, have fun with it. For more information take a look at the wiki and the examples