subscriber
received two pieces of data: one normal data and one empty data
#1819
-
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hello @willnufe, This is happening because you are using both Why are you receiving an additional empty message in sub_service? What is the solution? # no publisher decorator here
@router.subscriber("test")
async def message_consumer(m):
try:
....
response_dict = {}
....
except Exception as e:
log.logger.error(f"[messageConsumerInner]: {e}")
finally:
start_time = int(time.time() * 1000)
await kafka_broker.publish(Message2(**response_dict), KAFKA_TOPIC)
end_time = int(time.time() * 1000)
log.logger.info(f"[sendKafka]: {end_time - start_time}ms || {file_name}") Or just return the message object and let the decorator take care of publishing @kafka_broker.publisher(KAFKA_TOPIC)
@router.subscriber("test")
async def message_consumer(m):
try:
....
response_dict = {}
....
except Exception as e:
log.logger.error(f"[messageConsumerInner]: {e}")
finally:
# no kafka_broker.publish here
return Message2(**response_dict) Please pick one and use it. You shouldn't have the problem anymore. Sorry for the late reply. |
Beta Was this translation helpful? Give feedback.
Hello @willnufe,
This is happening because you are using both
await kafka_broker.publish
and@kafka_broker.publisher(KAFKA_TOPIC)
. Please pick either one of it and stick with it.Why are you receiving an additional empty message in sub_service?
The normal data was published in
await kafka_broker.publish
line itself and the empty data is published by decorator, which publishes whatever message returned by function. In you case there are no explicit return statements. So, by default,None
is returned and that is published as empty data.What is the solution?
Either explicitly publish it: