Project

em-postman

0.0
No commit activity in last 3 years
No release in over 3 years
EventMachine pub/sub using Redis list, resilient to failure
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0

Runtime

 Project Readme

Getting started

Postman is an EventMachine Pub/Sub resilient to failure. Postman uses Redis lists (brpop and lpush) to send messages to subscribers into a mailbox.

Postman has been designed to be resilient to failure on both side: publisher and subscriber. If your postman process dies or need to be restarted, it will be able to collect again messages from its mailbox.

Example

Server postbox: (server.rb)

require 'em-postman'

EM.run {
  postman = EM::Postman.new('server')
  postman.onmessage(:greetings) {|data|
    puts data.inspect
    postman.send_message data['from'], :greetings, {:message => 'hello ' + data['from']}
  }

  postman.listen
}

Client postbox: (client.rb)

require 'em-postman'

EM.run {
  postman = EM::Postman.new('client-' + Process.pid.to_s)
  postman.onmessage(:greetings) {|data|
    puts data.inspect
    EM.stop
  }

  postman.send_message 'server', :greetings, {:message => 'hello server', :from => postman.mailbox}
  postman.listen
}

em-synchrony

To use em-postman with em-synchrony

require 'em-synchrony/em-hiredis'
require 'em-postman/synchrony'

Credits

  • This gem has been extracted from http://pandastream.com.
  • Thanks to Jonas Pfenniger(zimbatm) and Martyn Loughran(mloughran)

License

The MIT License - Copyright (c) 2011 Vivien Schilis