add message queue support

This commit is contained in:
2024-01-05 17:01:16 +01:00
parent fcc5e571e9
commit 5b21b35f05
4 changed files with 47 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
import pika
QUEUE_HOST = "appointment.lpaconsulting.fr"
REQUEST_DATA_QUEUE = 'REQUEST_DATA'
credentials = pika.PlainCredentials('appointment', 'ZyuhJZ2xEYWhElhpJjy7YEpZGZwNYJz2fHIu')
class Receiver:
def __init__(self):
self.connection = None
self.channel = None
def set_up_connection(self):
self.connection = pika.BlockingConnection(
pika.ConnectionParameters(host=QUEUE_HOST, port=5672, credentials=credentials))
self.channel = self.connection.channel()
def listen_to_queue(self, callback):
self.channel.basic_qos(prefetch_count=1)
self.channel.basic_consume(queue=REQUEST_DATA_QUEUE, auto_ack=False, on_message_callback=callback)
self.channel.start_consuming()
# def on_message(ch, method, properties, body):
# print(f" [x] Received {body}")
# sender = Sender(str(body))
# contact_list = read_contacts('/Users/panlei/Desktop/yahoo_aol_valid_26-1.xlsx')
# sub_contact_list = contact_list[200:300]
# for con in sub_contact_list:
# if not is_already_sent(con):
# time.sleep(random.randint(2, 10))
# can_continue = sender.send_request(HERMES_REGISTER, con)
# if not can_continue:
# print("cannot continue")
# break
# else:
# print(con.mail + "--> skip")
# print(con.mail)
#
#
# if __name__ == '__main__':
# receiver = Receiver()
# receiver.set_up_connection()
# receiver.listen_to_queue(on_message)