GithubHelp home page GithubHelp logo

pdcarv / msgr Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jgraichen/msgr

0.0 1.0 0.0 578 KB

A Rails-like Messaging Framework.

License: MIT License

Ruby 89.87% JavaScript 1.13% CSS 1.03% HTML 7.98%

msgr's Introduction

Msgr: Rails-like Messaging Framework

Gem Version Build Status Coverage Status Code Climate Dependency Status RubyDoc Documentation

You know it and you like it. Using Rails you can just declare your routes and create a controller. That's all you need to process requests.

With Msgr you can do the same for asynchronous AMQP messaging. Just define your routes, create your consumer and watch you app processing messages.

Note: Msgr is still under heavy development.

Installation

Add this line to your application's Gemfile:

gem 'msgr'

And then execute:

$ bundle

Or install it yourself as:

$ gem install msgr

Usage

After adding 'msgr' to your gemfile create a config/rabbitmq.yml like this:

common: &common
  uri: amqp://localhost/

test:
  <<: *common

development:
  <<: *common

production:
  <<: *common

Specify your messaging routes in config/msgr.rb:

route 'local.test.index', to: 'test#index'
route 'local.test.another_action', to: 'test#another_action'

Create your consumer in app/consumers:

class TestConsumer < Msgr::Consumer
  def index
    data = { fuubar: 'abc' }

    publish data, to: 'local.test.another_action'
  end

  def another_action
    puts "#{payload.inspect}"
  end
end

Use Msgr.publish in to publish a message:

class TestController < ApplicationController
  def index
    @data = { abc: 'abc' }

    Msgr.publish @data, to: 'local.test.index'

    render nothing: true
  end
end

Msgr and fork web server like unicorn

Per default msgr opens the rabbitmq connect when rails is loaded. If you use a multi-process web server that preloads the application (like unicorn) will lead to unexpected behavior. In this case adjust config/rabbitmq.yml and adjust autostart = false:

common: &common
  uri: amqp://localhost/
  autostart: false

And call inside each worker Msgr.start - e.g. in an after-fork block

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

msgr's People

Contributors

jgraichen avatar mswart avatar

Watchers

Pedro Carvalho 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.