Package io.debezium.kafka
Class KafkaServer
java.lang.Object
io.debezium.kafka.KafkaServer
A small embedded Kafka server.
- Author:
- Randall Hauch
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate kafka.zk.AdminZkClientprivate final intprivate final Propertiesstatic final intprivate intprivate static final org.slf4j.Loggerprivate Fileprivate intprivate kafka.server.KafkaServer -
Constructor Summary
ConstructorsConstructorDescriptionKafkaServer(Supplier<String> zookeeperConnection) Create a new server instance.KafkaServer(Supplier<String> zookeeperConnection, int brokerId) Create a new server instance.KafkaServer(Supplier<String> zookeeperConnection, int brokerId, int port) Create a new server instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected intbrokerId()config()Get a copy of the complete configuration that is or will be used by the running server.voidcreateTopic(String topic, int numPartitions, int replicationFactor) Create the specified topic.voidcreateTopics(int numPartitions, int replicationFactor, String... topics) Create the specified topics.voidcreateTopics(String... topics) Create the specified topics.voidDelete all of the data associated with this server.kafka.zk.AdminZkClientGet the Zookeeper admin client used by the running Kafka server.Get the connection string.Get the parent directory where the broker's state will be kept.(package private) voidonEachDirectory(Consumer<File> consumer) Perform the supplied function on each directory used by this server.protected voidSet the initial default configuration properties.setPort(int port) Set the port for the server.setProperties(Properties properties) Set multiple configuration properties.setProperty(String name, String value) Set a configuration property.voidsetStateDirectory(File stateDirectory) Set the parent directory where the broker's state will be kept.voidshutdown(boolean deleteLogs) Shutdown the embedded Kafka server and delete all data.startup()Start the embedded Kafka server.toString()protected String
-
Field Details
-
DEFAULT_BROKER_ID
public static final int DEFAULT_BROKER_ID- See Also:
-
LOGGER
private static final org.slf4j.Logger LOGGER -
zkConnection
-
brokerId
private final int brokerId -
logsDir
-
config
-
desiredPort
private volatile int desiredPort -
port
private volatile int port -
server
private volatile kafka.server.KafkaServer server -
adminZkClient
private volatile kafka.zk.AdminZkClient adminZkClient
-
-
Constructor Details
-
KafkaServer
Create a new server instance.- Parameters:
zookeeperConnection- the supplier of the Zookeeper connection string; may not be null
-
KafkaServer
Create a new server instance.- Parameters:
zookeeperConnection- the supplier of the Zookeeper connection string; may not be nullbrokerId- the unique broker ID
-
KafkaServer
Create a new server instance.- Parameters:
zookeeperConnection- the supplier of the Zookeeper connection string; may not be nullbrokerId- the unique broker IDport- the desired port
-
-
Method Details
-
brokerId
protected int brokerId() -
zookeeperConnection
-
populateDefaultConfiguration
Set the initial default configuration properties. This method is called from the constructors and can be overridden to customize these properties.- Parameters:
props- the configuration properties; never null
-
setProperty
Set a configuration property. Several key properties that deal with Zookeeper, and the broker ID, may not be set via this method and are ignored since they are controlled elsewhere in this instance.- Parameters:
name- the property name; may not be nullvalue- the property value; may be null- Returns:
- this instance to allow chaining methods; never null
- Throws:
IllegalStateException- if the server is running when this method is called
-
setProperties
Set multiple configuration properties. Several key properties that deal with Zookeeper, the host name, and the broker ID, may not be set via this method and are ignored since they are controlled elsewhere in this instance.- Parameters:
properties- the configuration properties; may be null or empty- Returns:
- this instance to allow chaining methods; never null
- Throws:
IllegalStateException- if the server is running when this method is called
-
setPort
Set the port for the server.- Parameters:
port- the desired port, or-1if a random available port should be found and used- Returns:
- this instance to allow chaining methods; never null
-
config
Get a copy of the complete configuration that is or will be used by the running server.- Returns:
- the properties for the currently-running server; may be empty if not running
-
getConnection
Get the connection string. If the server is notrunningand the port is to be dynamically discovered upon startup, then this method returns "localhost:-1".- Returns:
- the connection string; never null
-
startup
Start the embedded Kafka server.- Returns:
- this instance to allow chaining methods; never null
- Throws:
IllegalStateException- if the server is already running
-
shutdown
public void shutdown(boolean deleteLogs) Shutdown the embedded Kafka server and delete all data.- Parameters:
deleteLogs- whether or not to remove all the log files after shutting down
-
deleteData
public void deleteData()Delete all of the data associated with this server. -
getAdminZkClient
public kafka.zk.AdminZkClient getAdminZkClient()Get the Zookeeper admin client used by the running Kafka server.- Returns:
- the Zookeeper admin client, or null if the Kafka server is not running
-
createTopics
Create the specified topics.- Parameters:
topics- the names of the topics to create
-
createTopics
Create the specified topics.- Parameters:
numPartitions- the number of partitions for each topicreplicationFactor- the replication factor for each topictopics- the names of the topics to create
-
createTopic
Create the specified topic.- Parameters:
topic- the name of the topic to createnumPartitions- the number of partitions for the topicreplicationFactor- the replication factor for the topic
-
onEachDirectory
Perform the supplied function on each directory used by this server.- Parameters:
consumer- the consumer function; may not be null
-
getStateDirectory
Get the parent directory where the broker's state will be kept. The broker will create a subdirectory for itself under this directory.- Returns:
- the parent directory for the broker's state; may be null if a temporary directory will be used
-
setStateDirectory
Set the parent directory where the broker's state will be kept. The broker will create a subdirectory for itself under this directory.- Parameters:
stateDirectory- the parent directory for the broker's state; may be null if a temporary directory will be used- Throws:
IllegalArgumentException- if the supplied file is not a directory or not writable
-
toString
-