28 lines
929 B
Python
28 lines
929 B
Python
import logging
|
|
import threading
|
|
from datetime import datetime
|
|
|
|
import pika
|
|
|
|
APPOINTMENT_QUEUE = "APPOINTMENT_QUEUE"
|
|
|
|
|
|
class MessageReceiver:
|
|
def __init__(self):
|
|
self._credentials = pika.PlainCredentials('scrapy_rabbitmq', '4x!hReCbA5v3heKWfPJV-Y')
|
|
|
|
def start_listener(self, callback):
|
|
t = threading.Thread(target=self._run, args=(callback,))
|
|
t.start()
|
|
|
|
def _run(self, callback):
|
|
connection = pika.BlockingConnection(
|
|
pika.ConnectionParameters(host='rabbitmq.lpaconsulting.fr', port=6672, credentials=self._credentials))
|
|
channel = connection.channel()
|
|
channel.queue_declare(queue=APPOINTMENT_QUEUE)
|
|
channel.basic_consume(queue=APPOINTMENT_QUEUE,
|
|
auto_ack=True,
|
|
on_message_callback=callback)
|
|
print(' [*] Waiting for messages. To exit press CTRL+C')
|
|
channel.start_consuming()
|