Class EphemeralKafkaCluster

java.lang.Object
com.github.charithe.kafka.EphemeralKafkaCluster
All Implemented Interfaces:
AutoCloseable

public class EphemeralKafkaCluster extends Object implements AutoCloseable
  • Method Details

    • create

      public static EphemeralKafkaCluster create(int numBroker) throws Exception
      Create a new ephemeral Kafka cluster
      Parameters:
      numBroker - number of brokers
      Returns:
      EphemeralKafkaCluster
      Throws:
      Exception - if create fails
    • create

      public static EphemeralKafkaCluster create(int numBroker, int zookeeperPort) throws Exception
      Create a new ephemeral Kafka cluster with the specified Zookeeper port
      Parameters:
      numBroker - Number of brokers
      zookeeperPort - Port the Zookeeper should listen on
      Returns:
      EphemeralKafkaCluster
      Throws:
      Exception - if create fails
    • create

      public static EphemeralKafkaCluster create(int numBroker, int zookeeperPort, Properties brokerProperties) throws Exception
      Create a new ephemeral Kafka cluster with the specified Zookeeper port and broker properties
      Parameters:
      numBroker - Number of brokers
      zookeeperPort - Port the Zookeeper should listen on
      brokerProperties - Override properties for all brokers in the cluster
      Returns:
      EphemeralKafkaCluster
      Throws:
      Exception - if create fails
    • isHealthy

      public boolean isHealthy()
    • isRunning

      public boolean isRunning()
    • stop

      Throws:
      IOException
      ExecutionException
      InterruptedException
    • getBrokers

      public List<EphemeralKafkaBroker> getBrokers()
    • connectionString

      public String connectionString()
    • producerConfig

      public Properties producerConfig()
      Create a minimal producer configuration that can be used to produce to this broker
      Returns:
      Properties
    • consumerConfig

      public Properties consumerConfig()
      Create a minimal consumer configuration with auto commit enabled. Offset is set to "earliest".
      Returns:
      Properies
    • consumerConfig

      public Properties consumerConfig(boolean enableAutoCommit)
      Create a minimal consumer configuration. Offset is set to "earliest".
      Parameters:
      enableAutoCommit - Enable auto commit
      Returns:
      Properties
    • createTopics

      public void createTopics(String... topics) throws ExecutionException, InterruptedException
      Throws:
      ExecutionException
      InterruptedException
    • close

      public void close() throws Exception
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception