Interface KafkaInt
- All Known Implementing Classes:
Kafka
-
Method Summary
Modifier and TypeMethodDescriptionvoidcreateTopic(String topic) Creates a topic with one partition.voidcreateTopic(String topic, int partitionsCount) Creates a topic with multiple partitions.voiddeleteTopic(String topic) Deletes a topic.net.bugreaper.core.assertable.AssertableStringListReturns a list of all topic names.intgetMessagesCountInTopic(String topic) Returns the number of messages in a topic.intgetPartitionsCount(String topic) Returns the number of partitions in a topic.net.bugreaper.core.assertable.AssertableStringListgrabMessagesFromTopic(String topic) Grabs messages from a topic using a consumer without committing offsets.net.bugreaper.core.assertable.AssertableStringListgrabMessagesFromTopic(String topic, String key) Grabs messages from a topic using a consumer without committing offsets.voidpurgeTopic(String topic) Purges a topic by removing messages from all partitions.voidsendToTopic(String topic, String message) Sends a message to a topic.voidsendToTopicWithKey(String topic, String key, String message) Sends a message with a key to a topic.
-
Method Details
-
createTopic
Creates a topic with one partition.- Parameters:
topic- topic name- Throws:
KafkaHelperException- if topic creation failsA warning is logged if the topic already exists.
-
createTopic
Creates a topic with multiple partitions.- Parameters:
topic- topic namepartitionsCount- number of partitions- Throws:
KafkaHelperException- if topic creation failsA warning is logged if the topic already exists.
-
deleteTopic
Deletes a topic.- Parameters:
topic- topic name- Throws:
KafkaHelperException- if topic deletion fails or the topic does not exist
-
purgeTopic
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
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 namemessage- message content- Throws:
KafkaHelperException- if sending the message failsThe topic is created automatically if it does not exist.
-
sendToTopicWithKey
Sends a message with a key to a topic.There may be a delay before the consumer can see the message
- Parameters:
topic- topic namekey- message key included in the Kafka recordmessage- message content- Throws:
KafkaHelperException- if sending the message failsThe topic is created automatically if it does not exist.
-
grabMessagesFromTopic
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 expiresKafkaHelperException- if the topic does not exist or the consumer timeout is reached
-
grabMessagesFromTopic
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 namekey- message key to filter consumed records- Returns:
AssertableStringList- Throws:
org.awaitility.core.ConditionTimeoutException- if the topic remains empty until the await timeout expiresKafkaHelperException- 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
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
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
-