def start(self): RabbitMQ.declareExchange(self.channel, self.exchange, _type="topic") queue = self.channel.queue_declare() queue_name = queue.method.queue self.channel.queue_bind(exchange=self.exchange, queue=queue_name, routing_key=self.routing_key) self.channel.basic_consume(self.onMessage, no_ack=True) self.channel.start_consuming()
def start(self): RabbitMQ.declareExchange(self.channel, self.exchange, _type="topic") queue = self.channel.queue_declare() queue_name = queue.method.queue self.channel.queue_bind(exchange=self.exchange, queue=queue_name, routing_key=self.routing_key) self.channel.basic_consume(self.onMessage, no_ack=True) self.channel.start_consuming()
def hello_IoT_world(): # establish connection host = "131.227.92.55" port = 8007 rabbitmqconnection, rabbitmqchannel = RabbitMQ.establishConnection(host, port) # declare exchange exchange = 'Social_data' topic1 = 'Aarhus' topic2 = 'Aarhus.Traffic.SensorID002' RabbitMQ.declareExchange(rabbitmqchannel, exchange, _type="topic") json = make_message() RabbitMQ.sendMessage(json, rabbitmqchannel, exchange, topic1) time.sleep(10)
def __init__(self, exchange, key, seconds_delay, repetitions): self.config = JOb(file(os.path.join(os.path.dirname(__file__), "..", "virtualisation", "config.json"), "rb")) self.host = self.config.rabbitmq.host self.port = self.config.rabbitmq.port print "Start listening on", self.host, "with port", self.port print "Waiting for topic", key, "on exchange", exchange self.connection, self.channel = RabbitMQ.establishConnection(self.host, self.port) self.exchange = exchange self.routing_key = key RabbitMQ.declareExchange(self.channel, self.exchange, _type='topic') self.seconds_delay = seconds_delay self.repetitions = repetitions self.timer = None self.q = Queue() self.lock = Lock()
shell=True) sys.path.remove(JAVA_DIR) # Multi-view Learning os.chdir(workingDir) fix_SENNA_result(SENNA_DIR + "/trans-temporal-clean-Tweets-senna.txt", Sleep) dict_data = get_result( NOW, trans_df, raw_df, result_folder + city + '-trans-temporal-Tweets-CNN.txt', data_folder + "trans-temporal-Tweets-9Dict.txt", data_folder + "temporal-Tweets-Location.txt") counter = 0 dict_data_df = pd.DataFrame(dict_data) if dict_data: RabbitMQ.declareExchange(rabbitmqchannel, exchange, _type="topic") for item in dict_data_df.Type: #['Type']: tmp_topic = topic + '.' + item temporal_message = serializeEvent( dict_data_df.Id[counter], dict_data_df.Name[counter], 'Twitter.Aarhus', dict_data_df.Level[counter], dict_data_df.Loc[counter], dict_data_df.Type[counter], dict_data_df.Time[counter]) print(temporal_message) #temporal_message=json.dumps(tmp_dict_data, sort_keys = True) RabbitMQ.sendMessage(temporal_message, rabbitmqchannel, exchange, tmp_topic) counter += 1 time.sleep(10) Sleep = Sleep + 10 stop = datetime.datetime.now()
subprocess.call('java -cp eventannotation.jar org.ccsr.datacollection.createtrainingdata.AnnotateTweetsEvents', shell=True) if os.path.isfile(data_folder+"temporal-Tweets-Location.txt"): os.remove(data_folder+"temporal-Tweets-Location.txt") subprocess.call('java -cp eventannotation.jar org.ccsr.datacollection.createtrainingdata.AnnotateTweetsLocations', shell=True) sys.path.remove(JAVA_DIR) # Multi-view Learning os.chdir(workingDir) fix_SENNA_result(SENNA_DIR+"/trans-temporal-clean-Tweets-senna.txt",Sleep) dict_data=get_result(NOW,trans_df,raw_df,result_folder+city+'-trans-temporal-Tweets-CNN.txt',data_folder+"trans-temporal-Tweets-9Dict.txt",data_folder+"temporal-Tweets-Location.txt") counter=0 dict_data_df=pd.DataFrame(dict_data) if dict_data: RabbitMQ.declareExchange(rabbitmqchannel, exchange, _type="topic") for item in dict_data_df.Type:#['Type']: tmp_topic=topic+'.'+item temporal_message=serializeEvent(dict_data_df.Id[counter], dict_data_df.Name[counter],'Twitter.Aarhus',dict_data_df.Level[counter],dict_data_df.Loc[counter], dict_data_df.Type[counter],dict_data_df.Time[counter]) print(temporal_message) #temporal_message=json.dumps(tmp_dict_data, sort_keys = True) RabbitMQ.sendMessage(temporal_message, rabbitmqchannel, exchange, tmp_topic) counter+=1 time.sleep(10) Sleep=Sleep+10 stop=datetime.datetime.now() processing_time=stop-start print 'Processing time: '+ str(processing_time) if ED_flag: NOW=Now+Step else: