make producer infi

This commit is contained in:
2026-04-14 21:54:20 +00:00
parent 0eeefa377d
commit 7ef72a0446
+14 -11
View File
@@ -1,4 +1,5 @@
import pika import pika
import time
import json import json
conn = pika.BlockingConnection(pika.ConnectionParameters("localhost")) conn = pika.BlockingConnection(pika.ConnectionParameters("localhost"))
@@ -21,18 +22,20 @@ orders = [
"should_fail": False, "retry_count": 0}, "should_fail": False, "retry_count": 0},
] ]
for order in orders: while True:
body = json.dumps(order) for order in orders:
ch.basic_publish( time.sleep(1)
exchange="orders.x", body = json.dumps(order)
routing_key="order.created", # as in the bindings ch.basic_publish(
body=body, exchange="orders.x",
properties=pika.BasicProperties( routing_key="order.created", # as in the bindings
delivery_mode=2, # persistent msg, committed to disk before ack body=body,
content_type="application/json" properties=pika.BasicProperties(
delivery_mode=2, # persistent msg, committed to disk before ack
content_type="application/json"
)
) )
)
print(f"published order {order['order_id']}") print(f"published order {order['order_id']}")
conn.close() conn.close()