public class LocalStandaloneKafkaResource extends Object implements KafkaResource
KafkaResource
that downloads kafka and sets up a local kafka cluster with the bundled
zookeeper.Modifier and Type | Method and Description |
---|---|
void |
afterTestFailure() |
void |
afterTestSuccess() |
void |
before() |
void |
createTopic(int replicationFactor,
int numPartitions,
String topic)
Creates a topic with the given name, replication factor and number of partitions.
|
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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
get
apply
public void before() throws Exception
before
in interface ExternalResource
Exception
public void afterTestSuccess()
afterTestSuccess
in interface ExternalResource
public void afterTestFailure()
afterTestFailure
in interface ExternalResource
public void createTopic(int replicationFactor, int numPartitions, String topic) throws IOException
KafkaResource
createTopic
in interface KafkaResource
replicationFactor
- replication factornumPartitions
- number of partitionstopic
- desired topic nameIOException
public void sendMessages(String topic, String... messages) throws IOException
KafkaResource
sendMessages
in interface KafkaResource
topic
- topic namemessages
- messages to sendIOException
public void sendKeyedMessages(String topic, String keySeparator, String... messages) throws IOException
KafkaResource
keySeparator
.sendKeyedMessages
in interface KafkaResource
topic
- topic namekeySeparator
- the separator used to parse key from value in the messagesmessages
- messages to sendIOException
public List<String> readMessage(int expectedNumMessages, String groupId, String topic) throws IOException
KafkaResource
expectedNumMessages
from the given topic. If we can't read the expected number
of messages we throw an exception.readMessage
in interface KafkaResource
expectedNumMessages
- expected number of messages that should be readgroupId
- group id to identify consumertopic
- topic nameIOException
public void setNumPartitions(int numPartitions, String topic) throws IOException
KafkaResource
setNumPartitions
in interface KafkaResource
numPartitions
- desired number of partitionstopic
- topic to modifyIOException
public int getNumPartitions(String topic) throws IOException
KafkaResource
getNumPartitions
in interface KafkaResource
topic
- topic nameIOException
public long getPartitionOffset(String topic, int partition) throws IOException
KafkaResource
getPartitionOffset
in interface KafkaResource
topic
- topic namepartition
- topic partitionIOException
public Collection<InetSocketAddress> getBootstrapServerAddresses()
KafkaResource
getBootstrapServerAddresses
in interface KafkaResource
public InetSocketAddress getZookeeperAddress()
KafkaResource
getZookeeperAddress
in interface KafkaResource
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.