@ThreadSafe public class KafkaServer extends Object
| Modifier and Type | Field and Description |
|---|---|
private kafka.zk.AdminZkClient |
adminZkClient |
private int |
brokerId |
private Properties |
config |
static int |
DEFAULT_BROKER_ID |
private int |
desiredPort |
private static org.slf4j.Logger |
LOGGER |
private File |
logsDir |
private int |
port |
private kafka.server.KafkaServer |
server |
private Supplier<String> |
zkConnection |
| Constructor and Description |
|---|
KafkaServer(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.
|
| Modifier and Type | Method and Description |
|---|---|
protected int |
brokerId() |
Properties |
config()
Get a copy of the complete configuration that is or will be used by the running server.
|
void |
createTopic(String topic,
int numPartitions,
int replicationFactor)
Create the specified topic.
|
void |
createTopics(int numPartitions,
int replicationFactor,
String... topics)
Create the specified topics.
|
void |
createTopics(String... topics)
Create the specified topics.
|
void |
deleteData()
Delete all of the data associated with this server.
|
kafka.zk.AdminZkClient |
getAdminZkClient()
Get the Zookeeper admin client used by the running Kafka server.
|
String |
getConnection()
Get the connection string.
|
File |
getStateDirectory()
Get the parent directory where the broker's state will be kept.
|
(package private) void |
onEachDirectory(Consumer<File> consumer)
Perform the supplied function on each directory used by this server.
|
protected void |
populateDefaultConfiguration(Properties props)
Set the initial default configuration properties.
|
KafkaServer |
setPort(int port)
Set the port for the server.
|
KafkaServer |
setProperties(Properties properties)
Set multiple configuration properties.
|
KafkaServer |
setProperty(String name,
String value)
Set a configuration property.
|
void |
setStateDirectory(File stateDirectory)
Set the parent directory where the broker's state will be kept.
|
void |
shutdown(boolean deleteLogs)
Shutdown the embedded Kafka server and delete all data.
|
KafkaServer |
startup()
Start the embedded Kafka server.
|
String |
toString() |
protected String |
zookeeperConnection() |
public static final int DEFAULT_BROKER_ID
private static final org.slf4j.Logger LOGGER
private final int brokerId
private volatile File logsDir
private final Properties config
private volatile int desiredPort
private volatile int port
private volatile kafka.server.KafkaServer server
private volatile kafka.zk.AdminZkClient adminZkClient
public KafkaServer(Supplier<String> zookeeperConnection)
zookeeperConnection - the supplier of the Zookeeper connection string; may not be nullpublic KafkaServer(Supplier<String> zookeeperConnection, int brokerId)
zookeeperConnection - the supplier of the Zookeeper connection string; may not be nullbrokerId - the unique broker IDprotected int brokerId()
protected String zookeeperConnection()
protected void populateDefaultConfiguration(Properties props)
props - the configuration properties; never nullpublic KafkaServer setProperty(String name, String value)
name - the property name; may not be nullvalue - the property value; may be nullIllegalStateException - if the server is running when this method is calledpublic KafkaServer setProperties(Properties properties)
properties - the configuration properties; may be null or emptyIllegalStateException - if the server is running when this method is calledpublic KafkaServer setPort(int port)
port - the desired port, or -1 if a random available port should be found and usedpublic Properties config()
public String getConnection()
running and the port is to be dynamically discovered
upon startup, then this method returns "localhost:-1".public KafkaServer startup()
IllegalStateException - if the server is already runningpublic void shutdown(boolean deleteLogs)
deleteLogs - whether or not to remove all the log files after shutting downpublic void deleteData()
public kafka.zk.AdminZkClient getAdminZkClient()
public void createTopics(String... topics)
topics - the names of the topics to createpublic void createTopics(int numPartitions,
int replicationFactor,
String... topics)
numPartitions - the number of partitions for each topicreplicationFactor - the replication factor for each topictopics - the names of the topics to createpublic void createTopic(String topic, int numPartitions, int replicationFactor)
topic - the name of the topic to createnumPartitions - the number of partitions for the topicreplicationFactor - the replication factor for the topicvoid onEachDirectory(Consumer<File> consumer)
consumer - the consumer function; may not be nullpublic File getStateDirectory()
public void setStateDirectory(File stateDirectory)
stateDirectory - the parent directory for the broker's state; may be null if a temporary directory will be usedIllegalArgumentException - if the supplied file is not a directory or not writableCopyright © 2020 JBoss by Red Hat. All rights reserved.