简体   繁体   English

包 kafka-clients 中的 AdminClient 线程安全吗?

[英]Is AdminClient in package kafka-clients thread safe?

I need to provide existention of kafka topic before producing events and default kafka topic autocreate is not adequate.我需要在生成事件之前提供 kafka 主题的存在,并且默认的 kafka 主题自动创建是不够的。 I have desided to use AdminClient class but I am worried about concurency issues.我已经决定使用 AdminClient 类,但我担心并发问题。
There is no information about thread safety AdminClient in documentation for Apache Kafka 2.2.x. Apache Kafka 2.2.x 的文档中没有关于线程安全AdminClient的信息。 Does somebody have any idea?有人有什么想法吗?

是的,Apache Kafka 的 AdminClient 是线程安全的,在它出现的每个版本的 Kafka 中。我们将创建一个 PR 来更新文档(我认为它已经在 J​​avaDoc 中了,但看起来没有。)

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. Kafka 的AdminClient旨在用于管理任务,因此不需要在需要线程安全的上下文中使用它。

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.如果您需要多个线程同时将AdminClient用于不同的任务,您可以简单地实例化它的多个实例,并单独使用它们,每个实例都在自己的线程中。 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的同一个实例。

The proposal section of the KIP states: KIP提案部分指出:

"The client will be multi-threaded; multiple threads will be able to safely make calls using the same AdminClient object." “客户端将是多线程的;多个线程将能够使用相同的 AdminClient 对象安全地进行调用。”

Beyond that, thread-safety of the Admin Client is not documented.除此之外,没有记录管理客户端的线程安全。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM