...
|
...
|
@@ -3,7 +3,7 @@ |
|
|
# @Author: wuxiao
|
|
|
# @Date: 2016-05-24 13:37:45
|
|
|
# @Last Modified by: anchen
|
|
|
# @Last Modified time: 2016-05-24 18:40:09
|
|
|
# @Last Modified time: 2016-06-16 18:36:19
|
|
|
|
|
|
import os
|
|
|
import sys
|
...
|
...
|
@@ -14,7 +14,9 @@ import json |
|
|
import time
|
|
|
import pika
|
|
|
from influxdb import InfluxDBClient
|
|
|
from pymongo import MongoClient
|
|
|
from lupa import LuaRuntime
|
|
|
from urllib import quote
|
|
|
|
|
|
'''
|
|
|
读取配置信息
|
...
|
...
|
@@ -37,6 +39,9 @@ channel = connection.channel() |
|
|
#连接influxdb
|
|
|
influxdb = InfluxDBClient(Config.influxdb_host, Config.influxdb_port, timeout=1)
|
|
|
|
|
|
#连接mongodb
|
|
|
mongodb = MongoClient( 'mongodb://%s:%s@%s:%d/' % ( quote(Config.mongodb_user),quote(Config.mongodb_pass),Config.mongodb_host,Config.mongodb_port ) )
|
|
|
|
|
|
print "MqClient:Start.\n";
|
|
|
|
|
|
#开始消费消息数据
|
...
|
...
|
@@ -73,10 +78,13 @@ for method_frame, properties, body in channel.consume(q_name): |
|
|
}
|
|
|
]
|
|
|
|
|
|
#选择库,写入
|
|
|
#influxdb选择库,写入
|
|
|
influxdb.switch_database(db)
|
|
|
influxdb.write_points(json_body)
|
|
|
|
|
|
#mongodb选择库和集合,写入
|
|
|
mongodb[db][measurement].insert_one(data['data'])
|
|
|
|
|
|
#ack回应
|
|
|
#channel.basic_ack(method_frame.delivery_tag)
|
|
|
if method_frame.delivery_tag % ack_interval == 0:
|
...
|
...
|
|