Interface KafkaInt

All Known Implementing Classes:
Kafka

public interface KafkaInt
Interface defines methods for facilitating helper interactions. Validates that all required methods are implemented.
  • Method Details

    • createTopic

      void createTopic(String topic)
      Creates a topic with one partition.
      Parameters:
      topic - topic name
      Throws:
      KafkaHelperException - if topic creation fails

      A warning is logged if the topic already exists.

    • createTopic

      void createTopic(String topic, int partitionsCount)
      Creates a topic with multiple partitions.
      Parameters:
      topic - topic name
      partitionsCount - number of partitions
      Throws:
      KafkaHelperException - if topic creation fails

      A warning is logged if the topic already exists.

    • deleteTopic

      void deleteTopic(String topic)
      Deletes a topic.
      Parameters:
      topic - topic name
      Throws:
      KafkaHelperException - if topic deletion fails or the topic does not exist
    • purgeTopic

      void purgeTopic(String topic)
      Purges a topic by removing messages from all partitions.
      Parameters:
      topic - topic name
      Throws:
      KafkaHelperException - if topic purge fails or the topic does not exist
    • sendToTopic

      void sendToTopic(String topic, String message)
      Sends a message to a topic.

      There may be a delay before the consumer can see the message, therefore await is used when consuming messages.

      Parameters:
      topic - topic name
      message - message content
      Throws:
      KafkaHelperException - if sending the message fails

      The topic is created automatically if it does not exist.

    • sendToTopicWithKey

      void sendToTopicWithKey(String topic, String key, String message)
      Sends a message with a key to a topic.

      There may be a delay before the consumer can see the message

      Parameters:
      topic - topic name
      key - message key included in the Kafka record
      message - message content
      Throws:
      KafkaHelperException - if sending the message fails

      The topic is created automatically if it does not exist.

    • grabMessagesFromTopic

      net.bugreaper.core.assertable.AssertableStringList grabMessagesFromTopic(String topic)
      Grabs messages from a topic using a consumer without committing offsets.

      Uses await until at least one message exists in the topic.

      The maximum number of messages is configured globally (only the latest messages are grabbed).

      Messages are returned in reverse order (newest messages first) to optimize processing when working with large amounts of data.

      Uses static consumer membership to reduce consumer rebalancing delays after reconnecting.

      Example: grabMessagesFromTopic("test_queue").seeListAnyEquals("my message")

      Parameters:
      topic - topic name
      Returns:
      AssertableStringList
      Throws:
      org.awaitility.core.ConditionTimeoutException - if the topic remains empty until the await timeout expires
      KafkaHelperException - if the topic does not exist or the consumer timeout is reached
    • grabMessagesFromTopic

      net.bugreaper.core.assertable.AssertableStringList grabMessagesFromTopic(String topic, String key)
      Grabs messages from a topic using a consumer without committing offsets.

      Uses await until at least one message exists in the topic.

      The maximum number of messages is configured globally (only the latest messages are grabbed).

      Messages are returned in reverse order (newest messages first) to optimize processing when working with large amounts of data.

      Uses static consumer membership to reduce consumer rebalancing delays after reconnecting.

      Example: grabMessagesFromTopic("test_topic", "my-key").seeListAnyEquals("my message")

      Parameters:
      topic - topic name
      key - message key to filter consumed records
      Returns:
      AssertableStringList
      Throws:
      org.awaitility.core.ConditionTimeoutException - if the topic remains empty until the await timeout expires
      KafkaHelperException - if the topic does not exist or the consumer timeout is reached
    • getAllTopicsNames

      net.bugreaper.core.assertable.AssertableStringList getAllTopicsNames()
      Returns a list of all topic names.

      Example: getAllTopicsNames().seeListAnyContains("test_topic")

      Returns:
      AssertableStringList
    • getMessagesCountInTopic

      int getMessagesCountInTopic(String topic)
      Returns the number of messages in a topic.
      Parameters:
      topic - topic name
      Returns:
      number of messages in the topic
      Throws:
      KafkaHelperException - if the topic does not exist
    • getPartitionsCount

      int getPartitionsCount(String topic)
      Returns the number of partitions in a topic.
      Parameters:
      topic - topic name
      Returns:
      number of partitions in the topic
      Throws:
      KafkaHelperException - if the topic does not exist