forked from waggle-sensor/beehive-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestServer.py
45 lines (36 loc) · 1.19 KB
/
TestServer.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
37
38
39
40
41
42
43
44
45
import sys
sys.path.append("../devtools/protocol_common")
import pika
from waggle_protocol.protocol.PacketHandler import *
import logging
import time
from waggle_protocol.utilities.gPickler import *
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.CRITICAL)
header_dict = {
"msg_mj_type" : ord('s'),
"msg_mi_type" : ord('d'),
}
data = ["test", 1, ['f'],'', [3.14], [''], ['TEST']]
params = pika.connection.URLParameters("amqp://waggle:waggle@localhost:5672/%2F")
connection = pika.BlockingConnection(params)
channel = connection.channel()
print("Channel to RabbitMQ opened.")
queue = "BenT240"
packer = pack(header_dict,gPickle(data))
for thing in packer:
packet = thing
channel.exchange_declare("waggle_in")
channel.queue_declare(queue)
channel.basic_publish(exchange="waggle_in",routing_key="in",body=packet)
def callback(ch,method,props,body):
print "Got something."
global connection
try:
msg = time.ctime(float(unpack(body)[1]))
print msg
except Exception as e:
print str(e)
finally:
ch.basic_ack(delivery_tag = method.delivery_tag)
channel.basic_consume(callback,queue = queue)
channel.start_consuming()