~ubuntu-branches/ubuntu/precise/pyzmq/precise

« back to all changes in this revision

Viewing changes to examples/heartbeat/heartbeater.py

  • Committer: Package Import Robot
  • Author(s): Debian Python Modules Team
  • Date: 2011-09-23 00:16:39 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: package-import@ubuntu.com-20110923001639-girjqodpb7uv17yu
Tags: 2.1.9-1
* New upstream version
  - should build on kFreeBSD without patches (Closes: #637777).
* Build-depend on zeromq 2.1.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
For use with heart.py
5
5
 
6
 
A basic heartbeater using PUB and XREP sockets. pings are sent out on the PUB, and hearts
7
 
are tracked based on their XREQ identities.
 
6
A basic heartbeater using PUB and ROUTER sockets. pings are sent out on the PUB, and hearts
 
7
are tracked based on their DEALER identities.
8
8
 
9
9
You can start many hearts with heart.py, and the heartbeater will monitor all of them, and notice when they stop responding.
10
10
 
21
21
class HeartBeater(object):
22
22
    """A basic HeartBeater class
23
23
    pingstream: a PUB stream
24
 
    pongstream: an XREP stream"""
 
24
    pongstream: an ROUTER stream"""
25
25
    
26
26
    def __init__(self, loop, pingstream, pongstream, period=1000):
27
27
        self.loop = loop
79
79
    context = zmq.Context()
80
80
    pub = context.socket(zmq.PUB)
81
81
    pub.bind('tcp://127.0.0.1:5555')
82
 
    xrep = context.socket(zmq.XREP)
83
 
    xrep.bind('tcp://127.0.0.1:5556')
 
82
    router = context.socket(zmq.ROUTER)
 
83
    router.bind('tcp://127.0.0.1:5556')
84
84
    
85
85
    outstream = zmqstream.ZMQStream(pub, loop)
86
 
    instream = zmqstream.ZMQStream(xrep, loop)
 
86
    instream = zmqstream.ZMQStream(router, loop)
87
87
    
88
88
    hb = HeartBeater(loop, outstream, instream)
89
89