Coder Social home page Coder Social logo

shoryuken's Introduction

Shoryuken

Shoryuken sho-ryu-ken is a super-efficient AWS SQS thread-based message processor.

Build Status Code Climate

Key features

Load balancing

Yeah, Shoryuken load balances the messages consumption!

Given this configuration:

concurrency: 25
delay: 25
queues:
  - [high_priority, 6]
  - [normal_priority, 2]
  - [low_priority, 1]

And supposing all the queues are full of messages, the configuration above will make Shoryuken to process high_priority 3 times more than normal_priority and 6 times more than low_priority, splitting the work load among all available processors concurrency: 25 .

If high_priority gets empty, Shoryuken will keep using the 25 processors, but only to process normal_priority and low_priority.

If high_priority receives a new message, Shoryuken will smoothly increase back its weight one by one until it reaches the weight of 6 again.

If a queue gets empty, Shoryuken will pause checking it for delay: 25.

Fetch in batches

To be even more performant and cost effective, Shoryuken fetches SQS messages in batches, so a single SQS request can fetch up to 10 messages.

Requirements

Ruby 2.0 or greater.

Installation

Add this line to your application's Gemfile:

gem 'shoryuken'

Or to get the latest updates:

gem 'shoryuken', github: 'phstc/shoryuken', branch: 'master'

And then execute:

$ bundle

Or install it yourself as:

$ gem install shoryuken

Usage

Worker class

class MyWorker
  include Shoryuken::Worker

  shoryuken_options queue: 'default', auto_delete: true
  # shoryuken_options queue: ->{ "#{ENV['environment']}_default" }

  # shoryuken_options body_parser: :json
  # shoryuken_options body_parser: ->(sqs_msg){ REXML::Document.new(sqs_msg.body) }
  # shoryuken_options body_parser: JSON

  def perform(sqs_msg, body)
    puts body
  end
end

Check the Worker options documention.

Sending a message

Check the Sending a message documentation

Middleware

class MyMiddleware
  def call(worker_instance, queue, sqs_msg, body)
    puts 'Before work'
    yield
    puts 'After work'
  end
end

Check the Middleware documentation.

Shoryuken Configuration

Sample configuration file shoryuken.yml.

concurrency: 25  # The number of allocated threads to process messages. Default 25
delay: 25        # The delay in seconds to pause a queue when it's empty. Default 0
queues:
  - [high_priority, 6]
  - [normal_priority, 2]
  - [low_priority, 1]

AWS Configuration

Check the Configure AWS Client documentation

Rails Integration

Check the Rails Integration Active Job documention.

Start Shoryuken

bundle exec shoryuken -r worker.rb -C shoryuken.yml

For other options check bundle exec shoryuken help start

SQS commands

Check also some available SQS commands bundle exec shoryuken help sqs, such as:

  • ls list queues
  • mv move messages from one queue to another
  • dump dump messages from a queue into a JSON lines file
  • requeue requeue messages from a dump file

More Information

For more information on advanced topics such as signals (shutdown), ActiveJob integration, and so on please check the Shoryuken Wiki.

Credits

Mike Perham, creator of Sidekiq, and everybody who contributed to it. Shoryuken wouldn't exist as it is without those contributions.

Contributing

  1. Fork it ( https://github.com/phstc/shoryuken/fork )
  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 a new Pull Request

shoryuken's People

Contributors

phstc avatar mariokostelac avatar leemhenson avatar elsurudo avatar farski avatar joekhoobyar avatar gshutler avatar atyndall avatar sschepens avatar vemv avatar kookster avatar richseviora avatar yusukegoto avatar lacour avatar potomak avatar serihiro avatar janpapenbrock avatar yujideveloper avatar yoshinorisano avatar avokhmin avatar sof31t avatar maysora avatar rkr090 avatar senjai avatar fourseven avatar gevans avatar fredsadaghiani avatar bobbrez avatar bbaja42 avatar agustin 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.