Created
August 17, 2022 14:52
-
-
Save dmcnulla/0bcbde6ec99092ea2511351762796c47 to your computer and use it in GitHub Desktop.
Revisions
-
dmcnulla created this gist
Aug 17, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ import requests from time import sleep import threading import json import pika from os import path QUEUE_NAME = "apex-durability-test" TEMP_FILE = 'results.txt' SERVER = 'http://10.25.148.82:31107/' HEADERS = {"Content-type": "application/json"} def main(): connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost')) channel = connection.channel() channel.queue_declare(queue=QUEUE_NAME, durable=True) def callback(ch, method, properties, body): print(body) message = json.loads(body.decode('utf-8')) file_name = path.join('/Users/david.mcnulla/IdeaProjects/apex', TEMP_FILE) with open(file_name, 'a') as f: f.write(f"{message['i']}\n") channel.basic_consume(queue=QUEUE_NAME, on_message_callback=callback, auto_ack=True) print(' [*] Waiting for messages. To exit press CTRL+C') channel.start_consuming() if __name__ == '__main__': thread = threading.Thread(target=main, args=[]) thread.start() for i in range(4021, 86400): msg = {"queue_name": QUEUE_NAME, "description": {"i": str(i)}} requests.post(url=SERVER, json=msg, headers=HEADERS) if i%2 == 0: sleep(1) thread.join()