public class LicenseTopicAdmin extends Object implements AutoCloseable
Admin.| Modifier and Type | Class and Description |
|---|---|
static class |
LicenseTopicAdmin.NewTopicBuilder
A builder of
NewTopic instances. |
static class |
LicenseTopicAdmin.TopicCreationResponse |
| Modifier and Type | Field and Description |
|---|---|
static LicenseTopicAdmin.TopicCreationResponse |
EMPTY_CREATION |
static int |
NO_PARTITIONS |
static short |
NO_REPLICATION_FACTOR |
| Constructor and Description |
|---|
LicenseTopicAdmin(Map<String,Object> adminConfig)
Create a new topic admin component with the given configuration.
|
LicenseTopicAdmin(Map<String,Object> adminConfig,
org.apache.kafka.clients.admin.Admin adminClient) |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
void |
close(Duration timeout) |
boolean |
createOrFindTopic(org.apache.kafka.clients.admin.NewTopic topic)
Attempt to find or create the topic described by the given definition, returning true if the topic was created or had
already existed, or false if the topic did not exist and could not be created.
|
LicenseTopicAdmin.TopicCreationResponse |
createOrFindTopics(org.apache.kafka.clients.admin.NewTopic... topics)
Attempt to create the topics described by the given definitions, returning all of the names of those topics that
were created by this request.
|
boolean |
createTopic(org.apache.kafka.clients.admin.NewTopic topic)
Attempt to create the topic described by the given definition, returning true if the topic was created or false
if the topic already existed.
|
Set<String> |
createTopics(org.apache.kafka.clients.admin.NewTopic... topics)
Attempt to create the topics described by the given definitions, returning all of the names of those topics that
were created by this request.
|
Set<String> |
createTopicsWithRetry(org.apache.kafka.clients.admin.NewTopic topicDescription,
long timeoutMs,
long backOffMs,
org.apache.kafka.common.utils.Time time)
Implements a retry logic around creating topic(s) in case it'd fail due to
specific type of exceptions, see
retryableTopicCreationException(ConnectException) |
static LicenseTopicAdmin.NewTopicBuilder |
defineTopic(String topicName)
Obtain a
builder to define a NewTopic. |
org.apache.kafka.clients.admin.Config |
describeTopicConfig(String topic)
Attempt to fetch the topic configuration for the given topic.
|
Map<String,org.apache.kafka.clients.admin.Config> |
describeTopicConfigs(String... topicNames)
Attempt to fetch the topic configurations for the given topics.
|
Map<String,org.apache.kafka.clients.admin.TopicDescription> |
describeTopics(String... topics)
Attempt to fetch the descriptions of the given topics
Apache Kafka added support for describing topics in 0.10.0.0, so this method works as expected with that and later versions.
|
Map<org.apache.kafka.common.TopicPartition,Long> |
endOffsets(Set<org.apache.kafka.common.TopicPartition> partitions)
Fetch the most recent offset for each of the supplied
TopicPartition objects. |
static org.apache.kafka.connect.errors.ConnectException |
maybeWrap(Throwable t,
String message) |
Map<org.apache.kafka.common.TopicPartition,Long> |
retryEndOffsets(Set<org.apache.kafka.common.TopicPartition> partitions,
Duration timeoutDuration,
long retryBackoffMs)
Fetch the most recent offset for each of the supplied
TopicPartition objects, and performs retry when
RetriableException is thrown. |
Set<String> |
topicCleanupPolicy(String topic)
Get the cleanup policy for a topic.
|
boolean |
verifyTopicCleanupPolicyOnlyCompact(String topic,
String workerTopicConfig,
String topicPurpose)
Verify the named topic uses only compaction for the cleanup policy.
|
public static final LicenseTopicAdmin.TopicCreationResponse EMPTY_CREATION
public static final int NO_PARTITIONS
public static final short NO_REPLICATION_FACTOR
public LicenseTopicAdmin(Map<String,Object> adminConfig)
Note that this will create an underlying Admin instance which must be freed when this
topic admin is no longer needed by calling close() or close(Duration).
adminConfig - the configuration for the Adminpublic static LicenseTopicAdmin.NewTopicBuilder defineTopic(String topicName)
builder to define a NewTopic.topicName - the name of the topicNewTopic description of the topic; never nullpublic boolean createTopic(org.apache.kafka.clients.admin.NewTopic topic)
topic - the specification of the topicorg.apache.kafka.connect.errors.ConnectException - if an error occurs, the operation takes too long, or the thread is interrupted while
attempting to perform this operationorg.apache.kafka.common.errors.UnsupportedVersionException - if the broker does not support the necessary APIs to perform this requestpublic Set<String> createTopics(org.apache.kafka.clients.admin.NewTopic... topics)
If multiple topic definitions have the same topic name, the last one with that name will be used.
Apache Kafka added support for creating topics in 0.10.1.0, so this method works as expected with that and later versions. With brokers older than 0.10.1.0, this method is unable to create topics and always returns an empty set.
topics - the specifications of the topicsorg.apache.kafka.connect.errors.ConnectException - if an error occurs, the operation takes too long, or the thread is interrupted while
attempting to perform this operationpublic Set<String> createTopicsWithRetry(org.apache.kafka.clients.admin.NewTopic topicDescription, long timeoutMs, long backOffMs, org.apache.kafka.common.utils.Time time)
retryableTopicCreationException(ConnectException)topicDescription - the specifications of the topictimeoutMs - Timeout in millisecondsbackOffMs - Time for delay after initial failed attempt in millisecondstime - Time instancecreateTopics(NewTopic...)public boolean createOrFindTopic(org.apache.kafka.clients.admin.NewTopic topic)
topic - the specification of the topicorg.apache.kafka.connect.errors.ConnectException - if an error occurs, the operation takes too long, or the thread is interrupted while
attempting to perform this operationorg.apache.kafka.common.errors.UnsupportedVersionException - if the broker does not support the necessary APIs to perform this requestpublic LicenseTopicAdmin.TopicCreationResponse createOrFindTopics(org.apache.kafka.clients.admin.NewTopic... topics)
If multiple topic definitions have the same topic name, the last one with that name will be used.
Apache Kafka added support for creating topics in 0.10.1.0, so this method works as expected with that and later versions. With brokers older than 0.10.1.0, this method is unable to create topics and always returns an empty set.
topics - the specifications of the topicsLicenseTopicAdmin.TopicCreationResponse with the names of the newly created and existing topics;
never null but possibly emptyorg.apache.kafka.connect.errors.ConnectException - if an error occurs, the operation takes too long, or the thread is interrupted while
attempting to perform this operationpublic Map<String,org.apache.kafka.clients.admin.TopicDescription> describeTopics(String... topics)
topics - the topics to describeorg.apache.kafka.connect.errors.RetriableException - if a retriable error occurs, the operation takes too long, or the
thread is interrupted while attempting to perform this operationorg.apache.kafka.connect.errors.ConnectException - if a non retriable error occurspublic boolean verifyTopicCleanupPolicyOnlyCompact(String topic, String workerTopicConfig, String topicPurpose)
topic - the name of the topicworkerTopicConfig - the name of the worker configuration that specifies the topic nameorg.apache.kafka.common.config.ConfigException - if the actual topic setting did not match the required settingpublic Set<String> topicCleanupPolicy(String topic)
topic - the name of the topicpublic org.apache.kafka.clients.admin.Config describeTopicConfig(String topic)
If the topic does not exist, a null value is returned.
topic - the name of the topic for which the topic configuration should be obtainedorg.apache.kafka.connect.errors.RetriableException - if a retriable error occurs, the operation takes too long, or the
thread is interrupted while attempting to perform this operationorg.apache.kafka.connect.errors.ConnectException - if a non retriable error occurspublic Map<String,org.apache.kafka.clients.admin.Config> describeTopicConfigs(String... topicNames)
An entry with a null Config is placed into the resulting map for any topic that does not exist on the brokers.
topicNames - the topics to obtain configurationsorg.apache.kafka.connect.errors.RetriableException - if a retriable error occurs, the operation takes too long, or the
thread is interrupted while attempting to perform this operationorg.apache.kafka.connect.errors.ConnectException - if a non retriable error occurspublic Map<org.apache.kafka.common.TopicPartition,Long> endOffsets(Set<org.apache.kafka.common.TopicPartition> partitions)
TopicPartition objects.partitions - the topic partitionsorg.apache.kafka.common.errors.UnsupportedVersionException - if the admin client cannot read end offsetsorg.apache.kafka.common.errors.TimeoutException - if the offset metadata could not be fetched before the amount of time allocated
by request.timeout.ms expires, and this call can be retriedorg.apache.kafka.common.errors.LeaderNotAvailableException - if the leader was not available and this call can be retriedorg.apache.kafka.connect.errors.RetriableException - if a retriable error occurs, or the thread is interrupted while attempting
to perform this operationorg.apache.kafka.connect.errors.ConnectException - if a non retriable error occurspublic Map<org.apache.kafka.common.TopicPartition,Long> retryEndOffsets(Set<org.apache.kafka.common.TopicPartition> partitions, Duration timeoutDuration, long retryBackoffMs)
TopicPartition objects, and performs retry when
RetriableException is thrown.partitions - the topic partitionstimeoutDuration - timeout duration; may not be nullretryBackoffMs - the number of milliseconds to delay upon receiving a
RetriableException before retrying again;
must be 0 or moreorg.apache.kafka.common.errors.UnsupportedVersionException - if the broker is too old to support the admin client API to read end offsetsorg.apache.kafka.connect.errors.ConnectException - if timeoutDuration is exhaustedendOffsets(Set)public static org.apache.kafka.connect.errors.ConnectException maybeWrap(Throwable t, String message)
public void close()
close in interface AutoCloseablepublic void close(Duration timeout)