|
@@ -0,0 +1,22 @@
|
|
1
|
+import pika
|
|
2
|
+
|
|
3
|
+class Consumer:
|
|
4
|
+ def __init__(self):
|
|
5
|
+ self.__url = 'dev-swh.ga'
|
|
6
|
+ self.__port = 5672
|
|
7
|
+ self.__vhost = '/'
|
|
8
|
+ self.__cred = pika.PlainCredentials('guest', 'guest')
|
|
9
|
+ self.__queue = 'py';
|
|
10
|
+
|
|
11
|
+ def on_message(channel, method_frame, header_frame, body):
|
|
12
|
+ print('Received %s' % body)
|
|
13
|
+
|
|
14
|
+ def main(self):
|
|
15
|
+ conn = pika.BlockingConnection(pika.ConnectionParameters(self.__url, self.__port, self.__vhost, self.__cred))
|
|
16
|
+ chan = conn.channel()
|
|
17
|
+ chan.basic_consume( queue = self.__queue, on_message_callback = Consumer.on_message, auto_ack = True )
|
|
18
|
+ print('Consumer is starting...')
|
|
19
|
+ chan.start_consuming()
|
|
20
|
+
|
|
21
|
+consumer = Consumer()
|
|
22
|
+consumer.main()
|