-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend.py
37 lines (28 loc) · 937 Bytes
/
send.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
32
33
34
35
36
#!/usr/bin/env python
# messaging.py
# Messaging bus for game play
# Kiat Huang <[email protected]>
import sys
import json
import pika
# get player's table key, seat key and bid
# example argument format '{"mytablekey": "MpnH72Sm", "myseatkey": "9fVNgmipwOPpeJ7olJ3nrqALbhRvOjL4", "mybid": "1N"}'
args = json.loads(sys.argv[1])
table_key = args.get("mytablekey")
seat_key = args.get("myseatkey")
bid = args.get("mybid")
# create a messaging bus
connection = pika.BlockingConnection(
pika.ConnectionParameters('localhost'))
channel = connection.channel()
# declare the queue with the supplied table key
channel.queue_declare(queue = table_key, durable=True)
# publish a bid!
channel.basic_publish(exchange = '',
routing_key = table_key,
body = sys.argv[1],
properties=pika.BasicProperties(
delivery_mode = 2 # make message persistent
))
print(" [x] Sent " + table_key)
connection.close()