Git Product home page Git Product logo

kanina's Introduction

Kanina

A Rails plugin that makes it easier for your models to communicate with RabbitMQ.

Gem Version Build Status Code Climate Inline docs API Documentation

Kanina abstracts away queue and exchange creation, so you can focus on the message and subscription side of things in Rails.

Prerequisites

You'll need RabbitMQ installed. Find instructions for your platform here.

Installation

Put this in your Gemfile:

gem 'kanina'

Then run bundle install to install the gem and its dependencies. Finally, run rails generate kanina:install to create bin/kanina and an amqp.yml.sample file in your config folder.

Copy amqp.yml.sample to amqp.yml, and change it to connect to your local RabbitMQ server. By default, it will connect to the one on your development machine, as long as you haven't changed the settings on it.

Sending Messages

Run the generator:

rails generate kanina:message MessageName

Then specify the name of the exchange, OR the routing key for the intended queue. To send a message, generate an instance of your new class, add data, and hit send:

msg = MessageName.new
msg.data = {key: "value"}
msg.deliver

You can also specify the type of exchange you want to create, like so:

class WeatherMessage < Kanina::Message
    fanout "reports"
end

Remember to use RabbitMQ's documentation to understand the rules governing how to use different types of exchanges, bindings, and queues appropriately. You don't have to create those things ahead of time with Kanina, but you do have to understand how they work!

Receiving messages

Generate a subscription with this command:

rails generate kanina:subscription SubscriptionName

Then tweak the resulting file to attach to the right queue, or use bindings to watch a named exchange. Use a subscribe block to define code that you want run when a message is received:

class NotifyUserSubscription < Kanina::Subscription
  subscribe queue: "notify_user" do |data|
    User.where(id: data[:id]).first.notify
  end
end

This project was written by Clinton Judy, and uses the ISC license.

kanina's People

Contributors

judy-zz avatar kthompson avatar

Stargazers

 avatar

Watchers

James Cloos avatar

kanina's Issues

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.