-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
31 lines (24 loc) · 836 Bytes
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import pika
import json
import random
import time
def publish_message():
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
channel.queue_declare(queue='documents')
while True:
document_id = random.randint(1, 1000)
status = random.choice(['processing', 'completed', 'failed'])
payload = {
'text': f"Document: {document_id} | status: {status} | timestamp{time.time()}"
}
channel.basic_publish(
exchange='',
routing_key='documents',
body=json.dumps(payload)
)
print(f" [x] Sent {payload}")
time.sleep(random.uniform(1, 5)) # Sleep for a random time between 1 and 5 seconds
connection.close()
if __name__ == "__main__":
publish_message()