-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsumer.py
executable file
·27 lines (20 loc) · 949 Bytes
/
consumer.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
#!/usr/bin/env python3
import pika
import subprocess
import os
import yaml
with open("config.yml", 'r') as ymlfile:
cfg = yaml.load(ymlfile)
credential_params = pika.PlainCredentials(cfg['rbmq']['user'],cfg['rbmq']['passwd'])
connection = pika.BlockingConnection(
pika.ConnectionParameters(host=cfg['rbmq']['host'],credentials=credential_params))
channel = connection.channel()
channel.queue_declare(queue=cfg['rbmq']['queue'])
def callback(ch, method, properties, body):
print(" [x] Received %r" % body)
encoding = 'utf-8'
rsync_cmd="/usr/bin/rsync -rvz -e 'ssh -p 2205' --bwlimit=1000 --progress root@" + cfg['rbmq']['host'] + ":" + str(body, encoding) + " " + cfg['rbmq']['remote_path']
os.system(rsync_cmd)
channel.basic_consume(queue=cfg['rbmq']['queue'], on_message_callback=callback, auto_ack=True)
print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()