Skip to content

vivienschilis/em-postman

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

EventMachine Pub/Sub resilient to failure

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages