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 |
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 maxNumMessages,
String groupId,
String topic)
Reads up to
maxNumMessages from 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
afterTestFailure, apply
public void before() throws Exception
before
in interface ExternalResource
Exception
public void afterTestSuccess()
afterTestSuccess
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 List<String> readMessage(int maxNumMessages, String groupId, String topic) throws IOException
KafkaResource
maxNumMessages
from the given topic.readMessage
in interface KafkaResource
maxNumMessages
- maximum 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–2020 The Apache Software Foundation. All rights reserved.