-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend-queue.py
More file actions
26 lines (24 loc) · 1.08 KB
/
Copy pathsend-queue.py
File metadata and controls
26 lines (24 loc) · 1.08 KB
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
#!/usr/bin/env python
import pendulum
import pika
import pika.credentials
import json
from fastnanoid import generate
from dlt.common.time import ensure_pendulum_datetime
connection = pika.BlockingConnection(
pika.ConnectionParameters(host='localhost', credentials=pika.credentials.PlainCredentials(username="user", password="password")))
channel = connection.channel()
channel.exchange_declare(exchange='test', exchange_type='topic', durable=True)
result = channel.queue_declare(queue="test_queue", durable=True, auto_delete=False, exclusive=False, arguments={
'x-queue-type': 'quorum',
})
queue_name = result.method.queue
channel.queue_bind(exchange='test', queue=queue_name, routing_key='hello')
for i in range(0, 1000, 1):
channel.basic_publish(exchange='test', routing_key='hello', body=json.dumps({"test_key": "test_value"}), properties=pika.spec.BasicProperties(
content_type="application/json",
message_id=generate(),
timestamp=ensure_pendulum_datetime(pendulum.now()).int_timestamp
))
print(" [x] Sent 'Hello World!'")
connection.close()