-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask.py
More file actions
31 lines (25 loc) · 762 Bytes
/
Copy pathtask.py
File metadata and controls
31 lines (25 loc) · 762 Bytes
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
#!/usr/bin/env python
import pika
import json
import postSchema_pb2 as pb
from google.protobuf.json_format import Parse
connection = pika.BlockingConnection(
pika.ConnectionParameters(host='localhost', port=5672))
channel = connection.channel()
channel.queue_declare(queue='task_queue', durable=True)
file = open('posts.json','r')
data = json.dumps(json.load(file))
file.close()
postList = Parse(data,pb.PostList())
print(type(postList))
for post in postList.posts:
message = post.SerializeToString()
channel.basic_publish(
exchange='',
routing_key='task_queue',
body=message,
properties=pika.BasicProperties(
delivery_mode=pika.spec.PERSISTENT_DELIVERY_MODE
))
print(" [x] Sent %r" % message)
connection.close()