-
Notifications
You must be signed in to change notification settings - Fork 0
/
gecko_demo.py
executable file
·49 lines (34 loc) · 1.12 KB
/
gecko_demo.py
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
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python2.7
"""
The intent here is to describe the usage model. This is gecko's
Hello World. A model to use in building your own amqp processors
using gecko.
"""
from pikaclient import PikaClient
import logging
import yaml
logging.basicConfig(level=logging.DEBUG)
class Processor(object):
def __init__(self):
"""
At some point this would take a config with resource configurations,
like database connection setup and stuff.
"""
pass
def process(self, msg):
"""
This demo uses one method for all parts of all messages.
"""
print "HANDLER: received a msg: %s" % msg
if __name__ == "__main__":
with open('test.yaml', 'r') as stream:
config = yaml.load(stream)
# create a consumer and processor.
consumer = PikaClient(config['AMQP'])
processor = Processor()
# tell the consumer about the processor. A design decision: we could've
# passed the processor to consumer's init, but this allows us to
# register multiple handlers if we want to.
consumer.register_handler(processor)
# FIRE!
consumer.run()