Git Product home page Git Product logo

aws-broker's Introduction

AWS Broker Gem Version

๐Ÿ“จ Ruby pub-sub on AWS


CircleCI

Background

This lightweight abstraction simplifies pub-sub on AWS's SNS and SQS services. Message processing is not part of this gem - we recommend using Shoryuken in addition to this gem.

Installation

gem 'aws-broker'

Basic Usage

Broker = Aws::Broker
topic = 'topic'
queue = 'queue'
message = { id: 0 }

# subscribe topic to specified queue
Broker.subscribe(topic, queue)

# subscribe topic to default queue (see wiki)
Broker.subscribe(topic)

# publish message to topic
Broker.publish(topic, message)

Rails Usage

Though AWS Broker does not require Rails, an ActiveRecord extension and accompanying RSpec matcher is provided if the project is Rails. This simplifies the process of publishing events for ActiveRecord create, update, and destroy callbacks.

Publishing

# app/models/user.rb
class User < ActiveRecord::Base
  publish_event :create, :update, :destroy
  # optionally override default topic name
  # self.publish_topic = :prefixed_user
end

The above is essentially shorthand for

# app/models/user.rb
class User < ActiveRecord::Base
  after_commit on: :create do
    Broker.publish(:user, event: :create, id: id)
  end
end

Testing

# spec/rails_helper.rb
require 'aws/broker/matchers'

# spec/models/user_spec.rb
describe User do
  context 'publish' do
    subject { User }
    it { should publish_event(:create) }
    it { should publish_event(:update) }
    it { should publish_event(:destroy) }
  end
end

Usage Details

See the wiki for an in-depth overview of usage and configuration options.

Inspiration

aws-broker's People

Contributors

drn avatar kirbycool avatar muneebaahmad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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