Skip to content

Commit

Permalink
BridgeConsumidorPersistencia finalizado
Browse files Browse the repository at this point in the history
  • Loading branch information
jd-vega11 authored Sep 27, 2017
1 parent f62791f commit 771bc4c
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Experimento1/BridgeKafkaPersistencia.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import json
import requests
from kafka import KafkaConsumer

consumer = KafkaConsumer('n1.a1.m1',
group_id='variablesAmbientales',
bootstrap_servers=['localhost:8090'])

for message in consumer:
json_data = json.loads(message.value.decode('utf-8'))
sensetime = json_data['sensetime']
value = json_data['variablesAmbientales']
ids = value[0]
nivelId = ids['nivelId']
areaId = ids['areaId']
microcontroladorId = ids['microcontroladorId']

for i in range(len(value)):
url = 'http://localhost:9000/minas/nivel/' + nivelId + '/areas/' + areaId + '/microcontroladores/'+microcontroladorId + '/sensor/'+ (i+1)+'/datos'
payload = {
'valor': (value[i+1])['data'],
'timeStamp':sensetime
}

response = requests.post(url, data=json.dumps(payload),
headers={'Content-type': 'application/json'})
print(message.topic)
print("Response Status Code: " + str(response.status_code))

0 comments on commit 771bc4c

Please sign in to comment.