3

I need to provide existention of kafka topic before producing events and default kafka topic autocreate is not adequate. I have desided to use AdminClient class but I am worried about concurency issues.
There is no information about thread safety AdminClient in documentation for Apache Kafka 2.2.x. Does somebody have any idea?

1
  • i don't think it is synchronized Commented Jul 15, 2019 at 11:34

3 Answers 3

6

Yes, Apache Kafka's AdminClient is thread-safe, in every version of Kafka which it appears in. We will create a PR to update the documentation (I thought it was in the JavaDoc already, but it looks like not.)

Sign up to request clarification or add additional context in comments.

Comments

0

The proposal section of the KIP states:

"The client will be multi-threaded; multiple threads will be able to safely make calls using the same AdminClient object."

Beyond that, thread-safety of the Admin Client is not documented.

Comments

-2

Kafka's AdminClient is intended to be used for administrative tasks, so there should be no need to use it in a context that requires thread-safety.

If you have a need for multiple threads to be using AdminClient for different tasks, simultaneously, you can simply instantiate multiple instances of it, and use them separately, each in its own thread. They will all do their thing separately, with no concurrency issues, since they don't need to talk to each other, or even know about each other. There is no need for multiple threads to access the same instance of AdminClient.

AdminClient instantiations are expensive as they need to establish a new connection. Add in SSL handshakes and the likes, and you can see why it makes sense to reuse an existing AdminClient. Hence, it's not a bad idea to have multiple threads access the same instance

Your Answer

Draft saved
Draft discarded

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.