Skip to content

Instantly share code, notes, and snippets.

@dmcnulla
Created August 17, 2022 14:52
Show Gist options
  • Select an option

  • Save dmcnulla/0bcbde6ec99092ea2511351762796c47 to your computer and use it in GitHub Desktop.

Select an option

Save dmcnulla/0bcbde6ec99092ea2511351762796c47 to your computer and use it in GitHub Desktop.

Revisions

  1. dmcnulla created this gist Aug 17, 2022.
    43 changes: 43 additions & 0 deletions test_sg2u.py
    Original 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()