-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproducer.py
More file actions
50 lines (37 loc) · 1.11 KB
/
producer.py
File metadata and controls
50 lines (37 loc) · 1.11 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2023 rzavalet <rzavalet@noemail.com>
#
# Distributed under terms of the MIT license.
"""
"""
import random
import string
from tembo_pgmq_python import Message, PGMQueue
if __name__ == '__main__':
host = "localhost"
port = 5432
username = "postgres"
password = "postgres"
database = "postgres"
num_messages = 10000
rnd = random.randint(0, 100)
test_queue = "bench_queue_sample"
queue = PGMQueue(host=host,
port=port,
username=username,
password=password,
database=database)
try:
#queue.drop_queue(test_queue)
queue.create_queue(test_queue)
for x in range(num_messages):
payload = ''.join(random.choices(string.ascii_uppercase + string.digits, k = 10))
msg = {"payload": payload}
msg_id = queue.send(test_queue, msg)
if (x+1) % 1000 == 0:
print("Sent {} messages".format(x + 1))
except Exception as e:
print(f"{e}")