~ubuntu-branches/ubuntu/wily/pyzmq/wily

« back to all changes in this revision

Viewing changes to examples/heartbeat/heartbeater.py

  • Committer: Package Import Robot
  • Author(s): Julian Taylor
  • Date: 2013-02-24 19:23:15 UTC
  • mfrom: (1.2.1) (9 sid)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: package-import@ubuntu.com-20130224192315-qhmwp3m3ymk8r60d
Tags: 2.2.0.1-1
* New upstream release
* relicense debian packaging to LGPL-3
* update watch file to use github directly
  thanks to Bart Martens for the file
* add autopkgtests
* drop obsolete DM-Upload-Allowed
* bump standard to 3.9.4, no changes required

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