0.01
No commit activity in last 3 years
No release in over 3 years
A Resque plugin. Provides a lightweight publish/subscribe messaging system, with message persistence when clients are down.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 1.9.10
 Project Readme

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_<topic_name>_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.