Stapfen makes it easy to write stand-alone Ruby workers to consume jobs from a STOMP-compatible work queue
Go to file
R. Tyler Croy 7413a033bd Make exit logic a bit more verbose/loggy.
Also invoking the java.lang.System.exit method when on the JVM to make sure
we're shutting down the JVM properly. I have my doubts that this is happening
currently
2013-10-21 10:48:37 -07:00
examples Add a main_thread method to allow for serializing some invocations on the main thread 2013-02-13 04:20:45 -08:00
lib Make exit logic a bit more verbose/loggy. 2013-10-21 10:48:37 -07:00
spec Make sure that evaluation of the log block happens in the instance instead of class 2013-10-03 16:12:16 -07:00
.gitignore Add some dependencies to the gemspec and Gemfile 2013-02-12 06:01:08 -08:00
CHANGES.md Make exit logic a bit more verbose/loggy. 2013-10-21 10:48:37 -07:00
Gemfile Handle running as a JMS-based Stapfen::Worker 2013-09-27 14:21:15 -07:00
Guardfile Add guard-rspec to make running the specs a little faster 2013-02-12 07:09:39 -08:00
LICENSE.txt Initial commit of bundler boiler plate 2013-02-12 05:52:58 -08:00
README.md Add a link to the generated RDocs 2013-10-03 16:19:59 -07:00
Rakefile Clean up the Rakefile and the gemspec for final (internal) consumption 2013-02-12 07:11:42 -08:00
stapfen.gemspec Handle running as a JMS-based Stapfen::Worker 2013-09-27 14:21:15 -07:00

README.md

Stapfen

Stapfen is a simple gem to make writing workers that consume messages via STOMP or JMS easier.

Stapfen allows you to write one worker class, and use either protocol depending on the environment and needs.

RDoc here

Usage

(Examples can be found in the examples/ directory)

Consider the following myworker.rb file:

class MyWorker < Stapfen::Worker
  use_stomp!

  configure do
    {
      :hosts => [
        {
          :host => 'localhost',
          :port => 61613,
          :login => 'guest',
          :passcode => 'guest',
          :ssl => false
        }
      ]
    }
  end

  # [Optional] Set up a logger for each worker instance
  log do
    Logger.new(STDOUT)
  end

  consume 'thequeue', :dead_letter_queue => '/queue/dlq',
                      :max_redeliveries => 0 do |message|

    data = expensive_computation(message.body)
    # Save my data, or do something worker-specific with it
    persist(data)

    # Send another message
    client.publish('/topic/computation-acks', "finished with #{message.message_id}")
  end

end

MyWorker.run!

When using the STOMP protocol, the value returned from the configure block is expected to be a valid Stomp::Client connection hash.

In the case of the JMS protocol, the value returned from the configure block is expected to be a valid configuration hash for the jruby-jms gem.


It is also important to note that the consume block will be invoked inside an instance of MyWorker and will execute inside its own Thread, so take care when accessing other shared resources.

STOMP-specific support

The consume block accepts the usual Stomp::Client subscription headers, as well as :dead_letter_queue and :max_redeliveries. If either of the latter two is present, the consumer will unreceive any messages for which the block returns false; after :max_redeliveries, it will send the message to :dead_letter_queue. consume blocks without these headers will fail silently rather than unreceive.

Installation

Add this line to your application's Gemfile:

gem 'stapfen'

And then execute:

$ bundle

Or install it yourself as:

$ gem install stapfen