Interface PubSubAdminAdapter

All Superinterfaces:
AutoCloseable, Closeable
All Known Implementing Classes:
ApacheKafkaAdminAdapter, MockInMemoryAdminAdapter

public interface PubSubAdminAdapter extends Closeable
An adapter for PubSubAdmin to create/delete/list/update topics. For APIs that do not have a timeout parameter, the default timeout is specified by PubSubConstants.PUBSUB_ADMIN_API_DEFAULT_TIMEOUT_MS.
  • Method Details

    • createTopic

      void createTopic(PubSubTopic pubSubTopic, int numPartitions, int replicationFactor, PubSubTopicConfiguration pubSubTopicConfiguration)
      Creates a new topic in the PubSub system with the given parameters.
      Parameters:
      pubSubTopic - The topic to be created.
      numPartitions - The number of partitions to be created for the topic.
      replicationFactor - The number of replicas for each partition.
      pubSubTopicConfiguration - Additional topic configuration such as retention, compaction policy, etc.
      Throws:
      IllegalArgumentException - If the replication factor is invalid.
      PubSubTopicExistsException - If a topic with the same name already exists.
      PubSubClientRetriableException - If the operation failed due to a retriable error.
      PubSubClientException - For all other issues related to the PubSub client.
    • deleteTopic

      void deleteTopic(PubSubTopic pubSubTopic, Duration timeout)
      Delete a given topic. The calling thread will block until the topic is deleted or the timeout is reached.
      Parameters:
      pubSubTopic - The topic to delete.
      timeout - The maximum duration to wait for the deletion to complete.
      Throws:
      PubSubTopicDoesNotExistException - If the topic does not exist.
      PubSubOpTimeoutException - If the operation times out.
      PubSubClientRetriableException - If the operation fails and can be retried.
      PubSubClientException - For all other issues related to the PubSub client.
    • getTopicConfig

      PubSubTopicConfiguration getTopicConfig(PubSubTopic pubSubTopic)
      Retrieves the configuration of a PubSub topic.
      Parameters:
      pubSubTopic - The PubSubTopic for which to retrieve the configuration.
      Returns:
      The configuration of the specified PubSubTopic as a PubSubTopicConfiguration object.
      Throws:
      PubSubTopicDoesNotExistException - If the specified PubSubTopic topic does not exist.
      PubSubClientRetriableException - If a retriable error occurs while attempting to retrieve the configuration.
      PubSubClientException - If an error occurs while attempting to retrieve the configuration or if the current thread is interrupted while attempting to retrieve the configuration.
    • getTopicConfigWithRetry

      default PubSubTopicConfiguration getTopicConfigWithRetry(PubSubTopic pubSubTopic)
    • listAllTopics

      Set<PubSubTopic> listAllTopics()
      Retrieves a set of all available PubSub topics from the PubSub cluster.
      Returns:
      A Set of PubSubTopic objects representing all available topics.
      Throws:
      PubSubClientRetriableException - If a retriable error occurs while attempting to retrieve the list of topics.
      PubSubClientException - If an error occurs while attempting to retrieve the list of topics or the current thread is interrupted while attempting to retrieve the list of topics.
    • setTopicConfig

      void setTopicConfig(PubSubTopic pubSubTopic, PubSubTopicConfiguration pubSubTopicConfiguration) throws PubSubTopicDoesNotExistException
      Sets the configuration for a PubSub topic.
      Parameters:
      pubSubTopic - The PubSubTopic for which to set the configuration.
      pubSubTopicConfiguration - The configuration to be set for the specified PubSub topic.
      Throws:
      PubSubTopicDoesNotExistException - If the specified PubSub topic does not exist.
      PubSubClientException - If an error occurs while attempting to set the topic configuration or if the current thread is interrupted while attempting to set the topic configuration.
    • containsTopic

      boolean containsTopic(PubSubTopic pubSubTopic)
      Checks if a PubSub topic exists.
      Parameters:
      pubSubTopic - The PubSubTopic to check for existence.
      Returns:
      true if the specified topic exists, false otherwise.
      Throws:
      PubSubClientRetriableException - If a retriable error occurs while attempting to check topic existence.
      PubSubClientException - If an error occurs while attempting to check topic existence.
    • containsTopicWithPartitionCheck

      boolean containsTopicWithPartitionCheck(PubSubTopicPartition pubSubTopicPartition)
      Checks if a PubSub topic exists and has the given partition
      Parameters:
      pubSubTopicPartition - The PubSubTopicPartition representing th topic and partition to check.
      Returns:
      true if the specified topic partition exists, false otherwise.
      Throws:
      PubSubClientRetriableException - If a retriable error occurs while attempting to check partition existence.
      PubSubClientException - If an error occurs while attempting to check partition existence or of the current thread is interrupted while attempting to check partition existence.
    • containsTopicWithExpectationAndRetry

      default boolean containsTopicWithExpectationAndRetry(PubSubTopic pubSubTopic, int maxAttempts, boolean expectedResult)
      Retry up to a maximum number of attempts to get the expected result. If the topic existence check returns with expected result, return the expected result immediately instead of retrying. This method exists since Kafka metadata is eventually consistent so that it takes time for all Kafka brokers to learn about a topic creation takes. So checking multiple times give us a more certain result of whether a topic exists.
      Parameters:
      pubSubTopic -
      maxAttempts - maximum number of attempts to check if no expected result is returned
      expectedResult - expected result
      Returns:
    • containsTopicWithPartitionCheckExpectationAndRetry

      default boolean containsTopicWithPartitionCheckExpectationAndRetry(PubSubTopicPartition pubSubTopicPartition, int maxAttempts, boolean expectedResult)
    • containsTopicWithExpectationAndRetry

      default boolean containsTopicWithExpectationAndRetry(PubSubTopic pubSubTopic, int maxAttempts, boolean expectedResult, Duration initialBackoff, Duration maxBackoff, Duration maxDuration)
    • containsTopicWithPartitionCheckExpectationAndRetry

      default boolean containsTopicWithPartitionCheckExpectationAndRetry(PubSubTopicPartition pubSubTopicPartition, int maxAttempts, boolean expectedResult, Duration attemptDuration)
    • getRetriableExceptions

      default List<Class<? extends Throwable>> getRetriableExceptions()
      Returns:
      Returns a list of exceptions that are retriable for this PubSubClient.
    • getAllTopicRetentions

      Map<PubSubTopic,Long> getAllTopicRetentions()
      Retrieves the retention settings for all PubSub topics.
      Returns:
      A map of pub-sub topics and their corresponding retention settings in milliseconds. If a topic does not have a retention setting, it will be mapped to PubSubConstants.PUBSUB_TOPIC_UNKNOWN_RETENTION.
      Throws:
      PubSubClientRetriableException - If a retriable error occurs while attempting to retrieve retention settings.
      PubSubClientException - If an error occurs while attempting to retrieve retention settings or if the current thread is interrupted while attempting to retrieve retention settings.
    • getClassName

      String getClassName()
    • getSomeTopicConfigs

      Map<PubSubTopic,PubSubTopicConfiguration> getSomeTopicConfigs(Set<PubSubTopic> pubSubTopics)
      Retrieves the configurations for a set of PubSub topics.
      Parameters:
      pubSubTopics - The set of PubSub topics to retrieve configurations for.
      Returns:
      A map of PubSub topics and their corresponding configurations.
      Throws:
      PubSubClientRetriableException - If a retriable error occurs while attempting to retrieve configurations.
      PubSubClientException - If an error occurs while attempting to retrieve configurations or if the current thread is interrupted while attempting to retrieve configurations.
    • getTopicConfigMaxRetryInMs

      default long getTopicConfigMaxRetryInMs()