public class EphemeralKafkaBroker extends Object
Modifier and Type | Method and Description |
---|---|
Properties |
consumerConfig()
Create a minimal consumer configuration with auto commit enabled.
|
Properties |
consumerConfig(boolean enableAutoCommit)
Create a minimal consumer configuration.
|
static EphemeralKafkaBroker |
create()
Create a new ephemeral Kafka broker with random broker port and Zookeeper port
|
static EphemeralKafkaBroker |
create(int kafkaPort)
Create a new ephemeral Kafka broker with the specified broker port and random Zookeeper port
|
static EphemeralKafkaBroker |
create(int kafkaPort,
int zookeeperPort)
Create a new ephemeral Kafka broker with the specified broker port and Zookeeper port
|
static EphemeralKafkaBroker |
create(int kafkaPort,
int zookeeperPort,
Properties overrideBrokerProperties)
Create a new ephemeral Kafka broker with the specified broker port, Zookeeper port and config overrides.
|
<K,V> org.apache.kafka.clients.consumer.KafkaConsumer<K,V> |
createConsumer(org.apache.kafka.common.serialization.Deserializer<K> keyDeserializer,
org.apache.kafka.common.serialization.Deserializer<V> valueDeserializer,
Properties overrideConfig)
Create a consumer that can read from this broker
|
<K,V> org.apache.kafka.clients.producer.KafkaProducer<K,V> |
createProducer(org.apache.kafka.common.serialization.Serializer<K> keySerializer,
org.apache.kafka.common.serialization.Serializer<V> valueSerializer,
Properties overrideConfig)
Create a producer that can write to this broker
|
Optional<String> |
getBrokerList()
Get the current broker list string
|
Optional<Integer> |
getKafkaPort()
Get the broker port
|
Optional<String> |
getLogDir()
Get the path to the Kafka log directory
|
Optional<String> |
getZookeeperConnectString()
Get the current Zookeeper connection string
|
Optional<Integer> |
getZookeeperPort()
Get the Zookeeper port
|
boolean |
isRunning()
Is the broker running?
|
Properties |
producerConfig()
Create a minimal producer configuration that can be used to produce to this broker
|
CompletableFuture<Void> |
start()
Start the Kafka broker
|
void |
stop()
Stop the Kafka broker
|
public static EphemeralKafkaBroker create()
public static EphemeralKafkaBroker create(int kafkaPort)
kafkaPort
- Port the broker should listen onpublic static EphemeralKafkaBroker create(int kafkaPort, int zookeeperPort)
kafkaPort
- Port the broker should listen onzookeeperPort
- Port the Zookeeper should listen onpublic static EphemeralKafkaBroker create(int kafkaPort, int zookeeperPort, Properties overrideBrokerProperties)
kafkaPort
- Port the broker should listen onzookeeperPort
- Port the Zookeeper should listen onoverrideBrokerProperties
- Broker properties to override. Pass null if there aren't any.public CompletableFuture<Void> start() throws Exception
Exception
public void stop()
public Properties producerConfig()
public Properties consumerConfig()
public Properties consumerConfig(boolean enableAutoCommit)
public <K,V> org.apache.kafka.clients.producer.KafkaProducer<K,V> createProducer(org.apache.kafka.common.serialization.Serializer<K> keySerializer, org.apache.kafka.common.serialization.Serializer<V> valueSerializer, Properties overrideConfig)
K
- Type of KeyV
- Type of ValuekeySerializer
- Key serializer classvalueSerializer
- Valuer serializer classoverrideConfig
- Producer config to override. Pass null if there aren't any.public <K,V> org.apache.kafka.clients.consumer.KafkaConsumer<K,V> createConsumer(org.apache.kafka.common.serialization.Deserializer<K> keyDeserializer, org.apache.kafka.common.serialization.Deserializer<V> valueDeserializer, Properties overrideConfig)
K
- Type of KeyV
- Type of ValuekeyDeserializer
- Key deserializervalueDeserializer
- Value deserializeroverrideConfig
- Consumer config to override. Pass null if there aren't anypublic Optional<Integer> getKafkaPort()
public Optional<Integer> getZookeeperPort()
public Optional<String> getLogDir()
public Optional<String> getZookeeperConnectString()
public Optional<String> getBrokerList()
public boolean isRunning()
Copyright © 2017. All rights reserved.