Giter Site home page Giter Site logo

messenger's Introduction

Messenger

Messenger communicates between the different services and is comprised of a listener and a worker.

Listeners

To create a listener in your application, run rails g messenger:listener <type>. Listeners must implement a listen method.

# Example app/messenger/listeners/something.rb
module Messenger
  module Listeners
    class Something
      include Messenger::Listeners

      def listen

        while true do
          # Get a message
          message = 'something'

          ensure_valid_worker

          @worker.work(message)
        end

      end

    end
  end
end

Another example listener is the SqsListener.

Workers

To create a listener in your application, run rails g messenger:worker <type>. Workers must implement a work method that accepts one parameter.

# Example app/messenger/workers/sidekiq.rb
module Messenger
  module Workers
    class Sidekiq
      include Messenger::Workers

      def work(message)
        BlueCollarWorker.perform_async(message)
      end

    end
  end
end

Installation

Add this line to your application's Gemfile:

gem 'messenger', git: '[email protected]:unbounce/messenger.git'

And then execute:

$ bundle

Configuration

You must set which listener and worker the messenger will use. To create a configuration file in your application, run rails g messenger:install. Set the appropriate type to your listener or worker type. This can be a child of Messenger::Listeners or Messenger::Workers or any other class.

# Example config/initializers/messenger.rb

Messenger.configure do |config|
  config.listener_type = :sqs
  config.worker_type = :sidekiq
end

Tell Rails where to find any listeners or workers you create:

# config/application.rb
config.autoload_paths << "#{Rails.root}/app/messenger"

Usage

The messenger can be run using rake messenger:listen or from the console using:

messenger = Messenger.new
messenger.listen

messenger's People

Contributors

jpb avatar

Watchers

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