23 lines
641 B
Python
23 lines
641 B
Python
import threading
|
|
|
|
from params import rabittmq_connection
|
|
|
|
APPOINTMENT_QUEUE = "APPOINTMENT_QUEUE"
|
|
|
|
|
|
class MessageReceiver:
|
|
|
|
def start_listener(self, callback):
|
|
t = threading.Thread(target=self._run, args=(callback,))
|
|
t.start()
|
|
|
|
def _run(self, callback):
|
|
|
|
channel = rabittmq_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()
|