public interface KafkaResource extends ExternalResource
Modifier and Type | Method and Description |
---|---|
void |
createTopic(int replicationFactor,
int numPartitions,
String topic)
Creates a topic with the given name, replication factor and number of partitions.
|
static KafkaResource |
get(String version)
Returns the configured KafkaResource implementation, or a
LocalStandaloneKafkaResource if none is configured. |
Collection<InetSocketAddress> |
getBootstrapServerAddresses()
Returns the kafka bootstrap server addresses.
|
int |
getNumPartitions(String topic)
Returns the current number of partitions for the given topic.
|
long |
getPartitionOffset(String topic,
int partition)
Returns the current partition offset for the given partition of the given topic.
|
InetSocketAddress |
getZookeeperAddress()
Returns the address of Zookeeper.
|
List<String> |
readMessage(int expectedNumMessages,
String groupId,
String topic)
Reads
expectedNumMessages from the given topic. |
void |
sendKeyedMessages(String topic,
String keySeparator,
String... messages)
Sends the given keyed messages to the given topic.
|
void |
sendMessages(String topic,
String... messages)
Sends the given messages to the given topic.
|
void |
setNumPartitions(int numPartitions,
String topic)
Modifies the number of partitions for the given topic.
|
afterTestFailure, afterTestSuccess, apply, before
void createTopic(int replicationFactor, int numPartitions, String topic) throws IOException
replicationFactor
- replication factornumPartitions
- number of partitionstopic
- desired topic nameIOException
void sendMessages(String topic, String... messages) throws IOException
topic
- topic namemessages
- messages to sendIOException
void sendKeyedMessages(String topic, String keySeparator, String... messages) throws IOException
keySeparator
.topic
- topic namekeySeparator
- the separator used to parse key from value in the messagesmessages
- messages to sendIOException
Collection<InetSocketAddress> getBootstrapServerAddresses()
InetSocketAddress getZookeeperAddress()
List<String> readMessage(int expectedNumMessages, String groupId, String topic) throws IOException
expectedNumMessages
from the given topic. If we can't read the expected number
of messages we throw an exception.expectedNumMessages
- expected number of messages that should be readgroupId
- group id to identify consumertopic
- topic nameIOException
void setNumPartitions(int numPartitions, String topic) throws IOException
numPartitions
- desired number of partitionstopic
- topic to modifyIOException
int getNumPartitions(String topic) throws IOException
topic
- topic nameIOException
long getPartitionOffset(String topic, int partition) throws IOException
topic
- topic namepartition
- topic partitionIOException
static KafkaResource get(String version)
LocalStandaloneKafkaResource
if none is configured.LocalStandaloneKafkaResource
if none is
configuredCopyright © 2014–2023 The Apache Software Foundation. All rights reserved.