コード例 #1
0
class LazarusProducer(Thread):

    def __init__(self, ip_address, topic='OryxInput', port='9092'):
        super(LazarusProducer, self).__init__()
        self.topic = topic  
        self.kafka = KafkaClient(ip_address + ':' + '9092')
        self.producer = SimpleProducer(self.kafka)
        self.energy = CornellEnergyDataset()
        #EnergyDataset()
        self.weather = MetroDataset()

    def _produce(self):
        date, curr_time = self.energy.current_time()
        data = { 'date': date,
                 'time' : curr_time,
                 'energy': self.energy.energy_consumption(),
                 'weather': self.weather.publish_data()} 
#	self.producer.ensure_topic_exists(self.topic)
        response = self.producer.send_messages(self.topic,json.dumps(data))
	print "\n\n"
	print data
	print "\n\n"
        #print response

    def run(self):
        while True:
            time.sleep(1)
            self._produce()
コード例 #2
0
 def __init__(self, ip_address, topic='OryxInput', port='9092'):
     super(LazarusProducer, self).__init__()
     self.topic = topic  
     self.kafka = KafkaClient(ip_address + ':' + '9092')
     self.producer = SimpleProducer(self.kafka)
     self.energy = CornellEnergyDataset()
     #EnergyDataset()
     self.weather = MetroDataset()