-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathkombu_sqs_subscriber.py
executable file
·67 lines (52 loc) · 1.76 KB
/
kombu_sqs_subscriber.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python
from spylunking.log.setup_logging import build_colorized_logger
from celery_connectors.utils import ev
from celery_connectors.kombu_subscriber import KombuSubscriber
name = "kombu-sqs-subscriber"
log = build_colorized_logger(
name=name)
log.info("Start - {}".format(name))
recv_msgs = []
def handle_message(body, message):
log.info(("callback received msg "
"body={}")
.format(body))
recv_msgs.append(body)
message.ack()
# end of handle_message
# Initialize KombuSubscriber
# http://docs.celeryproject.org/en/latest/getting-started/brokers/sqs.html
# https://github.com/celery/kombu/blob/master/kombu/transport/SQS.py
aws_key = ev(
"SQS_AWS_ACCESS_KEY",
"not_a_key")
aws_secret = ev(
"SQS_AWS_SECRET_KEY",
"not_a_secret")
sqs_auth_url = ev("BROKER_URL",
"sqs://{}:{}@".format(
aws_key,
aws_secret))
transport_options = {}
ssl_options = {}
sub = KombuSubscriber("kombu-sqs-subscriber",
sqs_auth_url,
ssl_options)
# sample: "sqs://ABCDEFGHIJKLMNOPQRST:ZYXK7NiynGlTogH8Nj+P9nlE73sq3@"
# ^ from the doc: 'you must remember to include the "@" at the end.'
# Now consume:
seconds_to_consume = 10.0
serializer = "application/json"
queue = "test1"
exchange = "test1"
routing_key = "test1"
transport_options = {"polling_interval": 0.3,
"visibility_timeout": 600}
sub.consume(callback=handle_message,
queue=queue,
exchange=exchange,
routing_key=routing_key,
serializer=serializer,
time_to_wait=seconds_to_consume,
transport_options=transport_options)
log.info("End - {}".format(name))