Package com.github.charithe.kafka
Class EphemeralKafkaBroker
java.lang.Object
com.github.charithe.kafka.EphemeralKafkaBroker
-
Method Summary
Modifier and TypeMethodDescriptionCreate a minimal consumer configuration with auto commit enabled.consumerConfig(boolean enableAutoCommit) Create a minimal consumer configuration.static EphemeralKafkaBrokercreate()Create a new ephemeral Kafka broker with random broker port and Zookeeper portstatic EphemeralKafkaBrokercreate(int kafkaPort) Create a new ephemeral Kafka broker with the specified broker port and random Zookeeper portstatic EphemeralKafkaBrokercreate(int kafkaPort, int zookeeperPort) Create a new ephemeral Kafka broker with the specified broker port and Zookeeper portstatic EphemeralKafkaBrokercreate(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 brokerGet the current broker list stringGet the broker portGet the path to the Kafka log directoryGet the current Zookeeper connection stringGet the Zookeeper portbooleanIs the broker running?Create a minimal producer configuration that can be used to produce to this brokerstart()voidstop()
-
Method Details
-
create
Create a new ephemeral Kafka broker with random broker port and Zookeeper port- Returns:
- EphemeralKafkaBroker
-
create
Create a new ephemeral Kafka broker with the specified broker port and random Zookeeper port- Parameters:
kafkaPort- Port the broker should listen on- Returns:
- EphemeralKafkaBroker
-
create
Create a new ephemeral Kafka broker with the specified broker port and Zookeeper port- Parameters:
kafkaPort- Port the broker should listen onzookeeperPort- Port the Zookeeper should listen on- Returns:
- EphemeralKafkaBroker
-
create
public 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.- Parameters:
kafkaPort- Port the broker should listen onzookeeperPort- Port the Zookeeper should listen onoverrideBrokerProperties- Broker properties to override. Pass null if there aren't any.- Returns:
- EphemeralKafkaBroker
-
start
- Throws:
Exception
-
stop
-
producerConfig
Create a minimal producer configuration that can be used to produce to this broker- Returns:
- Properties
-
consumerConfig
Create a minimal consumer configuration with auto commit enabled. Offset is set to "earliest".- Returns:
- Properies
-
consumerConfig
Create a minimal consumer configuration. Offset is set to "earliest".- Parameters:
enableAutoCommit- Enable auto commit- Returns:
- Properties
-
createProducer
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) Create a producer that can write to this broker- Type Parameters:
K- Type of KeyV- Type of Value- Parameters:
keySerializer- Key serializer classvalueSerializer- Valuer serializer classoverrideConfig- Producer config to override. Pass null if there aren't any.- Returns:
- KafkaProducer
-
createConsumer
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) Create a consumer that can read from this broker- Type Parameters:
K- Type of KeyV- Type of Value- Parameters:
keyDeserializer- Key deserializervalueDeserializer- Value deserializeroverrideConfig- Consumer config to override. Pass null if there aren't any- Returns:
- KafkaConsumer
-
getKafkaPort
Get the broker port- Returns:
- An optional that will only contain a value if the broker is running
-
getZookeeperPort
Get the Zookeeper port- Returns:
- An optional that will only contain a value if the broker is running
-
getLogDir
Get the path to the Kafka log directory- Returns:
- An Optional that will only contain a value if the broker is running
-
getZookeeperConnectString
Get the current Zookeeper connection string- Returns:
- An Optional that will only contain a value if the broker is running
-
getBrokerList
Get the current broker list string- Returns:
- An Optional that will only contain a value if the broker is running
-
isRunning
public boolean isRunning()Is the broker running?- Returns:
- True if the broker is running
-