Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Lightweight publish/subscribe messaging system, with persistence when clients are down, written on top of Redis and Resque
branch: master

This branch is 3 commits behind RevolutionPrep:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
examples
lib
test
HISTORY.md
MIT-LICENSE
README.md
Rakefile
init.rb
install.rb
resque-pubsub.gemspec
uninstall.rb

README.md

ResquePubsub

A Resque plugin. Requires Resque 1.9.10.

A lightweight publish/subscribe messaging system, with message persistence when clients are down, written on top of Redis and Resque.

Usage / Examples

A simple class that can publish a message:

class TestPublisher
  include Resque::Plugins::Pubsub::Publisher

  def some_method
    self.publish(topic, message)
  end
end

A simple class that subscribes to messages on a particular topic:

class TestSubscriber
  include Resque::Plugins::Pubsub::Subscriber

  subscribe 'test_topic'

  def self.read_test_topic_message(message)
    # Do something with the message
  end
end

Customize & Extend

The method that the is called when the subscriber is sent a message defaults to read__message, but can be customized with the option :reader_method, e.g.,

subscribe 'test_topic', :reader_message => :custom_message_method

The namespace that pubsub uses in Resque defaults to 'resque:pubsub' but can be configured by setting the constant Resque::Plugins::Pubsub::Exchange::PUBSUB_NAMESPACE.

Install

As a gem

$ gem install resque-pubsub

In a Rails app, as a plugin

$ rails plugin install git://github.com/Mechaferret/resque-pubsub.git

Running Resque

A sample config file is provided in examples/resque-pubsub.rb. If you put this in config/initializers for a Rails app, then Resque will default to the app namespace but will take an override on namespace from the environment variable RESQUE_NAMESPACE. Thus

QUEUE=* RESQUE_NAMESPACE="resque:pubsub" rake environment resque:work

will run resque jobs against the default pubsub namespace (i.e., will be the pubsub server)

while

QUEUE=* rake environment resque:work

will run resque in an app as normal.

Acknowledgements

Copyright (c) 2011 Monica McArthur, released under the MIT license.

Something went wrong with that request. Please try again.