本文整理汇总了Java中kafka.server.KafkaServerStartable.startup方法的典型用法代码示例。如果您正苦于以下问题:Java KafkaServerStartable.startup方法的具体用法?Java KafkaServerStartable.startup怎么用?Java KafkaServerStartable.startup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kafka.server.KafkaServerStartable
的用法示例。
在下文中一共展示了KafkaServerStartable.startup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: KafkaSourceEmbeddedKafka
import kafka.server.KafkaServerStartable; //导入方法依赖的package包/类
public KafkaSourceEmbeddedKafka(Properties properties) {
zookeeper = new KafkaSourceEmbeddedZookeeper(zkPort);
dir = new File(System.getProperty("java.io.tmpdir"), "kafka_log-" + UUID.randomUUID());
try {
FileUtils.deleteDirectory(dir);
} catch (IOException e) {
e.printStackTrace();
}
Properties props = new Properties();
props.put("zookeeper.connect",zookeeper.getConnectString());
props.put("broker.id","1");
props.put("host.name", "localhost");
props.put("port", String.valueOf(serverPort));
props.put("log.dir", dir.getAbsolutePath());
if (properties != null) {
props.putAll(properties);
}
KafkaConfig config = new KafkaConfig(props);
kafkaServer = new KafkaServerStartable(config);
kafkaServer.startup();
initProducer();
}
示例2: start
import kafka.server.KafkaServerStartable; //导入方法依赖的package包/类
/**
* Starts the Kafka broker.
*
* @throws IOException if an error occurs during initialization
*/
public synchronized void start() throws IOException {
log.info("Starting Kafka broker on port {}", port);
logsDir = Files.createTempDirectory(LocalKafkaBroker.class.getSimpleName());
logsDir.toFile().deleteOnExit();
kafkaServer = new KafkaServerStartable(new KafkaConfig(ConfigUtils.keyValueToProperties(
"broker.id", TEST_BROKER_ID,
"log.dirs", logsDir.toAbsolutePath(),
"listeners", "PLAINTEXT://:" + port,
"zookeeper.connect", "localhost:" + zkPort,
// Above are for Kafka 0.8; following are for 0.9+
"message.max.bytes", 1 << 26,
"replica.fetch.max.bytes", 1 << 26
), false));
kafkaServer.startup();
}
示例3: startServer
import kafka.server.KafkaServerStartable; //导入方法依赖的package包/类
public static KafkaServerStartable startServer(final int port, final int brokerId,
final String zkStr, final Properties configuration) {
// Create the ZK nodes for Kafka, if needed
int indexOfFirstSlash = zkStr.indexOf('/');
if (indexOfFirstSlash != -1) {
String bareZkUrl = zkStr.substring(0, indexOfFirstSlash);
String zkNodePath = zkStr.substring(indexOfFirstSlash);
ZkClient client = new ZkClient(bareZkUrl);
client.createPersistent(zkNodePath, true);
client.close();
}
File logDir = new File("/tmp/kafka-" + Double.toHexString(Math.random()));
logDir.mkdirs();
configureKafkaPort(configuration, port);
configureZkConnectionString(configuration, zkStr);
configureBrokerId(configuration, brokerId);
configureKafkaLogDirectory(configuration, logDir);
KafkaConfig config = new KafkaConfig(configuration);
KafkaServerStartable serverStartable = new KafkaServerStartable(config);
serverStartable.startup();
return serverStartable;
}
示例4: startServer
import kafka.server.KafkaServerStartable; //导入方法依赖的package包/类
public static KafkaServerStartable startServer(final int port, final int brokerId, final String zkStr,
final Properties configuration) {
// Create the ZK nodes for Kafka, if needed
int indexOfFirstSlash = zkStr.indexOf('/');
if (indexOfFirstSlash != -1) {
String bareZkUrl = zkStr.substring(0, indexOfFirstSlash);
String zkNodePath = zkStr.substring(indexOfFirstSlash);
ZkClient client = new ZkClient(bareZkUrl);
client.createPersistent(zkNodePath, true);
client.close();
}
File logDir = new File("/tmp/kafka-" + Double.toHexString(Math.random()));
logDir.mkdirs();
configureKafkaPort(configuration, port);
configureZkConnectionString(configuration, zkStr);
configureBrokerId(configuration, brokerId);
configureKafkaLogDirectory(configuration, logDir);
KafkaConfig config = new KafkaConfig(configuration);
KafkaServerStartable serverStartable = new KafkaServerStartable(config);
serverStartable.startup();
return serverStartable;
}
示例5: startServer
import kafka.server.KafkaServerStartable; //导入方法依赖的package包/类
public static KafkaServerStartable startServer(final int port, final int brokerId, final String zkStr,
final Properties configuration) {
// Create the ZK nodes for Kafka, if needed
int indexOfFirstSlash = zkStr.indexOf('/');
if (indexOfFirstSlash != -1) {
String bareZkUrl = zkStr.substring(0, indexOfFirstSlash);
String zkNodePath = zkStr.substring(indexOfFirstSlash);
ZkClient client = new ZkClient(bareZkUrl);
client.createPersistent(zkNodePath, true);
client.close();
}
File logDir = new File("/tmp/kafka-" + Double.toHexString(Math.random()));
logDir.mkdirs();
configuration.put("port", Integer.toString(port));
configuration.put("zookeeper.connect", zkStr);
configuration.put("broker.id", Integer.toString(brokerId));
configuration.put("log.dirs", logDir.getAbsolutePath());
KafkaConfig config = new KafkaConfig(configuration);
KafkaServerStartable serverStartable = new KafkaServerStartable(config);
serverStartable.startup();
return serverStartable;
}
示例6: TestKafkaServer
import kafka.server.KafkaServerStartable; //导入方法依赖的package包/类
public TestKafkaServer(Properties properties) {
String path = properties.getProperty("log.dir");
locate = Files.createTempDir();
File dir = new File(locate, path).getAbsoluteFile();
properties.setProperty("log.dir", dir.getAbsolutePath());
kafkaConfig = new KafkaConfig(properties);
System.out.println("num.partitions =" + kafkaConfig.numPartitions());
System.out.println("background.threads ="
+ kafkaConfig.backgroundThreads());
kafkaServer = new KafkaServerStartable(kafkaConfig);
try {
kafkaServer.startup();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("embedded kafka is up");
}
示例7: setupKafkaBroker
import kafka.server.KafkaServerStartable; //导入方法依赖的package包/类
private void setupKafkaBroker() {
try {
// mock zookeeper
zkTestServer = new TestingServer(2181);
// mock kafka
Properties props = new Properties();
props.put("broker.id", "0");
props.put("host.name", "localhost");
props.put("port", "9092");
props.put("log.dir", "/tmp/tmp_kafka_dir");
props.put("zookeeper.connect", zkTestServer.getConnectString());
props.put("replica.socket.timeout.ms", "1500");
KafkaConfig config = new KafkaConfig(props);
kafkaServer = new KafkaServerStartable(config);
kafkaServer.startup();
// create "sensordata" topic
ZkClient zkClient = new ZkClient(zkTestServer.getConnectString(), 10000, 10000, ZKStringSerializer$.MODULE$);
AdminUtils.createTopic(zkClient, "sensordata", 1, 1, new Properties());
zkClient.close();
} catch (Exception e) {
log.error("Error running local Kafka broker / Zookeeper", e);
}
}
示例8: LocalKafkaServer
import kafka.server.KafkaServerStartable; //导入方法依赖的package包/类
public LocalKafkaServer() throws IOException {
while (new File(logDir).exists()) {
FileUtils.deleteDirectory(new File(logDir));
}
Properties props = new Properties();
props.put("broker.id", nodeId);
props.put("port", port);
props.put("log.dir", logDir);
props.put("zookeeper.connect", zkConnect);
props.put("host.name", "127.0.0.1");
KafkaConfig conf = new KafkaConfig(props);
zkUtils = ZkUtils.apply(props.getProperty("zookeeper.connect"),
30000,
30000,
JaasUtils.isZkSecurityEnabled());
server = new KafkaServerStartable(conf);
server.startup();
}
示例9: startKafkaServer
import kafka.server.KafkaServerStartable; //导入方法依赖的package包/类
private static KafkaServerStartable startKafkaServer(int kafkaPort, int zkPort) {
File logDir;
try {
logDir = java.nio.file.Files.createTempDirectory("kafka-logs").toFile();
} catch (IOException e) {
throw new RuntimeException("Unable to create Kafka temp dirs!", e);
}
LOGGER.info("Kafka log dir: " + logDir.getAbsolutePath());
logDir.deleteOnExit();
Properties kafkaBrokerConfig = new Properties();
kafkaBrokerConfig.setProperty("zookeeper.connect", "127.0.0.1:" + zkPort);
kafkaBrokerConfig.setProperty("broker.id", "0");
kafkaBrokerConfig.setProperty("host.name", "127.0.0.1");
kafkaBrokerConfig.setProperty("port", Integer.toString(kafkaPort));
kafkaBrokerConfig.setProperty("log.dir", logDir.getAbsolutePath());
kafkaBrokerConfig.setProperty("log.flush.interval.messages", String.valueOf(1));
KafkaServerStartable broker = new KafkaServerStartable(new KafkaConfig(kafkaBrokerConfig));
broker.startup();
return broker;
}
示例10: setup
import kafka.server.KafkaServerStartable; //导入方法依赖的package包/类
@Override
public void setup()
throws Exception {
LOGGER.info("Starting up Kafka Server...");
FileUtils.deleteDirectory(KafkaTestUtils.DEFAULT_LOG_DIR);
final boolean success = KafkaTestUtils.DEFAULT_LOG_DIR.mkdir();
if (!success) {
LOGGER.warn("Unable to create Kafka log dir [" + KafkaTestUtils.DEFAULT_LOG_DIR.getAbsolutePath() + "]");
}
final KafkaConfig config = KafkaTestUtils.getKafkaBrokerConfig();
kafkaServer = new KafkaServerStartable(
config);
kafkaServer.startup();
Thread.sleep(3000);
}
示例11: KafkaLocal
import kafka.server.KafkaServerStartable; //导入方法依赖的package包/类
public KafkaLocal(Properties kafkaProperties) throws IOException, InterruptedException{
KafkaConfig kafkaConfig = new KafkaConfig(kafkaProperties);
//start local zookeeper
System.out.println("starting local zookeeper...");
zookeeper = new ZookeeperLocal();
try {
zookeeper.startzkServer(2181);
}
catch (Exception e) {
throw new RuntimeException("Error starting local zookeeper server", e);
}
System.out.println("done");
//start local kafka broker
kafka = new KafkaServerStartable(kafkaConfig);
System.out.println("starting local kafka broker...");
kafka.startup();
System.out.println("done");
}
示例12: start
import kafka.server.KafkaServerStartable; //导入方法依赖的package包/类
public void start(Properties props) throws Exception {
Integer port = getZkPort(props);
zk = new TestingServer(port, tempDir); // this starts the zk server
System.out.println("Started ZooKeeper: ");
System.out.println("--> Temp Directory: " + zk.getTempDirectory());
props.put("log.dirs", tempDir.getAbsolutePath());
KafkaConfig kafkaConfig = new KafkaConfig(props);
kafka = new KafkaServerStartable(kafkaConfig);
kafka.startup();
System.out.println("Started KAFKA: ");
}
示例13: start
import kafka.server.KafkaServerStartable; //导入方法依赖的package包/类
public void start(Properties properties) throws Exception {
Integer port = getZkPort(properties);
zk = new TestingServer(port);
zk.start();
KafkaConfig kafkaConfig = new KafkaConfig(properties);
kafka = new KafkaServerStartable(kafkaConfig);
kafka.startup();
}
示例14: startKafkaLocal
import kafka.server.KafkaServerStartable; //导入方法依赖的package包/类
private static void startKafkaLocal() throws Exception {
final File kafkaTmpLogsDir = File.createTempFile("zookeeper", "test");
if (kafkaTmpLogsDir.delete() && kafkaTmpLogsDir.mkdir()) {
Properties kafkaProperties = new Properties();
kafkaProperties.setProperty("host.name", HOSTNAME);
kafkaProperties.setProperty("port", String.valueOf(KAFKA_PORT));
kafkaProperties.setProperty("broker.id", String.valueOf(BROKER_ID));
kafkaProperties.setProperty("zookeeper.connect", ZOOKEEPER_CONNECT);
kafkaProperties.setProperty("log.dirs", kafkaTmpLogsDir.getAbsolutePath());
KafkaConfig kafkaConfig = new KafkaConfig(kafkaProperties);
KafkaServerStartable kafka = new KafkaServerStartable(kafkaConfig);
kafka.startup();
}
}
示例15: KafkaServer
import kafka.server.KafkaServerStartable; //导入方法依赖的package包/类
public KafkaServer(int zookeeperPort, int kafkaBrokerPort) {
try {
Preconditions.checkArgument(zookeeperPort > 0);
Preconditions.checkArgument(kafkaBrokerPort > 0);
this.zookeeperPort = zookeeperPort;
this.brokerPort = kafkaBrokerPort;
this.logDir = new File(System.getProperty("java.io.tmpdir"), "kafka/logs/hbase-cdc-kafka-" + brokerPort);
KafkaConfig config = buildKafkaConfig(zookeeperPort);
kafka = new KafkaServerStartable(config);
kafka.startup();
} catch (Exception ex) {
throw new RuntimeException("Could not start test broker", ex);
}
}