Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 36 lines (24 sloc) 0.827 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
#!/usr/bin/env python

import uuid

import logging
logging.basicConfig(level=logging.DEBUG)

import gevent
import gevent.monkey
gevent.monkey.patch_all()

from dashi import DashiConnection


class HeartbeatSubscriber(object):

    def __init__(self):
        self.topic = "sub"+uuid.uuid4().hex

    def start(self):
        self.dashi = DashiConnection(self.topic, "amqp://guest:guest@127.0.0.1//",
                "heartbeater")
        self.dashi.handle(self.heartbeat)
        consumer = gevent.spawn(self.dashi.consume)

        # send subscribe request
        ret = self.dashi.call("heartbeater", "subscribe", subscriber=self.topic)
        assert ret is True

        consumer.join()

    def heartbeat(self, beat):
        print "Got heartbeat: %s" % beat

if __name__ == '__main__':
    HeartbeatSubscriber().start()
Something went wrong with that request. Please try again.