Skip to content

Instantly share code, notes, and snippets.

@dmcnulla
Created August 17, 2022 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmcnulla/0bcbde6ec99092ea2511351762796c47 to your computer and use it in GitHub Desktop.
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.
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