Created
August 17, 2022 14:52
-
-
Save dmcnulla/0bcbde6ec99092ea2511351762796c47 to your computer and use it in GitHub Desktop.
Send many messages to sg2u and retrieve them from a queue to determine reliability of sg2u.
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 characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment