Coder Social home page Coder Social logo

amqp's Introduction

What AMQP gem is

Simple asynchronous AMQP driver for Ruby/EventMachine This library works with Ruby 1.8, Ruby 1.9, JRuby and Rubinius, and is licensed under the Ruby License.

This library was tested primarily with RabbitMQ, although it should be compatible with any server implementing the AMQP 0-8 spec.

Getting started

To use examples with RabbitMQ, first install the broker. If you have Mercurial and Erlang/OTP installed, here is how to do it in 4 lines:

hg clone http://hg.rabbitmq.com/rabbitmq-codegen
hg clone http://hg.rabbitmq.com/rabbitmq-server
cd rabbitmq-server
make run

Then have a look at the various bundled examples:

ruby examples/mq/pingpong.rb   # 1-1 communication using amq.direct
ruby examples/mq/clock.rb      # 1-N communication using amq.fanout
ruby examples/mq/stocks.rb     # 1-subscriber communication using amq.topic

ruby examples/mq/multiclock.rb # header based routing (new rabbitmq feature)
ruby examples/mq/ack.rb        # using ack
ruby examples/mq/pop.rb        # pop off messages one at a time

ruby examples/mq/hashtable.rb  # simple async rpc layer
ruby examples/mq/primes.rb 4   # parallelized prime number generation
ruby examples/mq/logger.rb     # simple logging api

For high level API documentation see MQ class. For more details into the lower level AMQP client API, run the simple client example:

ruby examples/amqp/simple.rb   # low-level AMQP api
ruby examples/mq/internal.rb   # low-level Queue/Exchange api

Or refer to protocol/doc.txt, which enumerates packets sent between a server and client during a typical session, in both binary and decoded formats.

How to use AMQP gem with Ruby on Rails, Merb, Sinatra and other web frameworks

To use AMQP gem from web applications, you would need to have EventMachine reactor running. If you use Thin, you are set: Thin uses EventMachine under the hook.

With other web servers, you need to start EventMachine reactor in it's own thread like this:

Thread.new { EM.run }

because otherwise EventMachine will block current thread. Then connect to AMQP broker:

AMQP.connect(:host => "localhost", :user => "guest", :pass => "guest", :vhost => "/")

In a Ruby on Rails app, probably the best place for this code is initializer (like config/initializers/amqp.rb). For Merb apps, it is config/init.rb. For Sinatra and pure Rack applications, place it next to other configuration code.

Same separate thread technique can be used to make EventMachine play nicely with other libraries that would block current thread (like File::Tail).

AMQP gem mailing list

Running specifications suite

To run the test suite make sure you have bacon gem installed and run:

rake spec

The lib/amqp/spec.rb file is generated automatically based on the AMQP specification. To generate it:

rake codegen

Credits and more information

(c) 2008โ€”2010 Aman Gupta (tmm1)

This project was inspired by py-amqplib, rabbitmq, qpid and rubbyt. Special thanks to Dmitriy Samovskiy, Ben Hood and Tony Garnock-Jones.

AMQP brokers

  • RabbitMQ (Rabbit Technologies, Erlang/OTP, MPL)
  • ZeroMQ (iMatix/FastMQ/Intel, C++, GPL3)
  • OpenAMQ (iMatix, C, GPL2)
  • ActiveMQ (Apache Foundation, Java, Apache2)

AMQP resources

Messaging and distributed systems resources

amqp's People

Contributors

tmm1 avatar wilson avatar cremes avatar michaelklishin avatar jakedouglas avatar dougbarth avatar abscondment avatar codahale avatar careo avatar dj2 avatar

Stargazers

Andrew Chase avatar

Watchers

James Cloos avatar  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.