-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot send messages when the topic is set long time after the broker #16
Comments
When "rd_kafka_brokers_add" is called, it will request metadata from Kafka clusters. If the code "sleep(1)" is put after "rd_kafka_brokers_add", the topics information will be ignored when the broker threads receive metadata since "rd_kafka_topic_new" has not been called so far. (Here, the metadata must be received within one second after the request is sent.) When "rd_kafka_topic_new" is called later, it will not request metadata from Kafka clusters again. Therefore, rdkafka can not send messages because it does not know to which broker the topic corresponds. I guess you may make a mistake. The upper debug output you pasted above corresponds to the case that you add the code "sleep(1)" while the lower corresponds to the case without the "sleep". You can see the output "Ignore unknown topic rb_event" in the upper debug infomation since "rd_kafka_topic_new" has not been called at that time. The output "new topic: rb_event" indicates the "rd_kafka_topic_new" is called later. Solving this issue is easy. Just swap the position of "rd_kafka_topic_new" and "rd_kafka_brokers_add". Call "rd_kafka_topic_new" firstly and then call "rd_kafka_brokers_add". Now the code "sleep(1)" will not affect the result. |
You are right in both auwzb. I swapped the debug output and I didn't realize I could just set the topic before the brokers. Anyway, I think the correct behavior is you can add a topic anywhere in the code, so I'll let the issue open by the moment. |
Hi, eugpermar. I am glad that my comment helped. |
I will push a fix for this soon. |
The message producer only works if you set the topic short time after the broker addittion. If you just put a sleep(1) between rd_brokers_add and rd_kafka_topic_new, rd_kafka_example cannot send messages anymore.
Here is the debug output: Without the sleep:
%7|1376053795.949|PARTCNT|0x7ff2168bf700|default#producer-0| Ignore unknown topic rb_event
%7|1376053795.949|METADATA|0x7ff2168bf700|default#producer-0| Topic #2/3: rb_event partition 0 Leader 0
%7|1376053795.949|TOPICUPD|0x7ff2168bf700|default#producer-0| Ignoring topic rb_event: not found locally
%7|1376053795.949|METADATA|0x7ff2168bf700|default#producer-0| Topic #2/3: rb_event partition 1 Leader 0
%7|1376053795.949|TOPICUPD|0x7ff2168bf700|default#producer-0| Ignoring topic rb_event: not found locally
%7|1376053795.949|METADATA|0x7ff2168bf700|default#producer-0| Topic #2/3: rb_event partition 2 Leader 0
%7|1376053795.949|TOPICUPD|0x7ff2168bf700|default#producer-0| Ignoring topic rb_event: not found locally
%7|1376053795.949|PARTCNT|0x7ff2168bf700|default#producer-0| Ignore unknown topic rb_event
%7|1376053799.159|TOPIC|0x7ff2184d1020|default#producer-0| new topic: rb_event
and when I add the sleep:
%7|1376053831.161|PARTCNT|0x7f762d015700|default#producer-0| No change in partition count for topic rb_event
%7|1376053831.161|METADATA|0x7f762d015700|default#producer-0| Topic #2/3: rb_event partition 0 Leader 0
%7|1376053831.161|TOPICUPD|0x7f762d015700|default#producer-0| No leader change for topic rb_event [0] with leader 0
%7|1376053831.161|METADATA|0x7f762d015700|default#producer-0| Topic #2/3: rb_event partition 1 Leader 0
%7|1376053831.161|TOPICUPD|0x7f762d015700|default#producer-0| No leader change for topic rb_event [1] with leader 0
%7|1376053831.161|METADATA|0x7f762d015700|default#producer-0| Topic #2/3: rb_event partition 2 Leader 0
%7|1376053831.161|TOPICUPD|0x7f762d015700|default#producer-0| No leader change for topic rb_event [2] with leader 0
%7|1376053831.161|PARTCNT|0x7f762d015700|default#producer-0| Partitioning 0 unassigned messages in topic rb_event to 3 partitions
%7|1376053831.161|UAS|0x7f762d015700|default#producer-0| 0/0 messages were partitioned
The text was updated successfully, but these errors were encountered: