Skip to content

subscriber received two pieces of data: one normal data and one empty data #1819

Answered by kumaranvpl
willnufe asked this question in Q&A
Discussion options

You must be logged in to vote

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:

# no publisher decorator here
@router.subscriber("test")
async def message_consumer(m):
	try:
		....
		r…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Lancetnik
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants