Skip to content
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

Question: How to detect (un)successful connection to a Kafka broker? #34

Open
tgudlek opened this issue Jan 15, 2018 · 3 comments
Open

Comments

@tgudlek
Copy link

tgudlek commented Jan 15, 2018

Hey!

I'm trying to use cppkafka and like it so far!

However, I can't seem to find a way to know what's going on with the connection itself.
I've set up a producer, but it seems to asynchronously throw once it determines a connection to a broker can't be established. Can I register a callback or use any other mechanism to capture/handle such situation myself instead of it crashing my binary?

Bonus question: is it possible to connect to a broker through Zookeeper's proxy rather than specify explicit broker list myself?

@mfontanini
Copy link
Owner

Can you expand on how it asynchronously throws? I tried using a bogus broker endpoint and it kept running forever trying to reconnect and never crashed. Can you show exactly what you're doing?

Using zookeeper is deprecated IIRC. On newer kafka versions the preferred way is having at least one broker endpoint and if there are more, the rest will be automatically discovered.

@erikbasargin
Copy link

erikbasargin commented Feb 8, 2018

If I understand you correctly, then when you call producer.flush() the exception throws.
I have this happen when the server is down, etc. I'm wrapping producer.flush() in block try { producer.flush(); } cach (...) {}.

And I set up callback:

  • set_delivery_report_callback([&](cppkafka::Producer &, const cppkafka::Message & message) {...})
  • set_error_callback([&](cppkafka::KafkaHandleBase &, int error, const std::string & reason){...})

In the first case, I look at the errors, not including 0 (success delivery) and -191 (for more information on errors, see message.h and rdkafka.h) - message.get_error().

In the second case, it is intuitively clear :).

Unfortunately, how to determine that the connection is successful without using the first callback I do not know. The very issue of concern.

@mfontanini
Copy link
Owner

Sorry it took me ages to reply. I think this question is more suitable to be done on the librdkafka repo as it seems to be implementation specific.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants