fix, no more infinite loops for consumer
This commit is contained in:
parent
6291bb483c
commit
7f88f87722
@ -21,7 +21,7 @@ class Manager:
|
||||
|
||||
self.dataPublisher = KafkaProducer(
|
||||
bootstrap_servers=['localhost:9092'],
|
||||
client_id=f'manager{id}',
|
||||
client_id=f'manager{id}_producer',
|
||||
value_serializer=lambda v: dumps(v).encode('utf-8')
|
||||
)
|
||||
|
||||
@ -30,6 +30,7 @@ class Manager:
|
||||
bootstrap_servers=['localhost:9092'],
|
||||
auto_offset_reset='earliest',
|
||||
enable_auto_commit=True,
|
||||
consumer_timeout_ms = 1000,
|
||||
group_id=f'manager{id}',
|
||||
value_deserializer=lambda x: loads(x.decode('utf-8'))
|
||||
)
|
||||
@ -39,20 +40,25 @@ class Manager:
|
||||
if message.value['id'] == self.id:
|
||||
print(f"Manager {self.id} received message: ")
|
||||
print(message.value)
|
||||
print("Updating info...\n")
|
||||
self.moisture = message.value['moisture']
|
||||
self.temp = message.value['temperature']
|
||||
print("Updating info...\n")
|
||||
|
||||
dataMessage = {
|
||||
'id' : self.id,
|
||||
'moisture' : self.moisture,
|
||||
'temp' : self.temp,
|
||||
self.sendData()
|
||||
|
||||
def sendData(self):
|
||||
print("sending data...")
|
||||
message = {
|
||||
'id': self.id,
|
||||
'moisture': self.moisture,
|
||||
'temp': self.temp,
|
||||
'valveStatus': str(self.valveStatus),
|
||||
'heaterStatus': str(self.heaterStatus),
|
||||
'isAutoOn' : self.isAutoOn
|
||||
'isAutoOn': self.isAutoOn
|
||||
}
|
||||
|
||||
self.dataPublisher.send('data', dataMessage)
|
||||
print(message)
|
||||
self.dataPublisher.send('data', message)
|
||||
|
||||
manager1 = Manager(id = 1)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user