當前位置: 首頁>>代碼示例>>Java>>正文


Java KafkaServerStartable.startup方法代碼示例

本文整理匯總了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();
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:23,代碼來源:KafkaSourceEmbeddedKafka.java

示例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();
}
 
開發者ID:oncewang,項目名稱:oryx2,代碼行數:23,代碼來源:LocalKafkaBroker.java

示例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;
}
 
開發者ID:uber,項目名稱:uReplicator,代碼行數:27,代碼來源:KafkaStarterUtils.java

示例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;
}
 
開發者ID:uber,項目名稱:chaperone,代碼行數:27,代碼來源:KafkaStarterUtils.java

示例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;
}
 
開發者ID:Hanmourang,項目名稱:Pinot,代碼行數:27,代碼來源:KafkaStarterUtils.java

示例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");
}
 
開發者ID:pulsarIO,項目名稱:jetstream,代碼行數:19,代碼來源:TestKafkaServer.java

示例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);
    }
}
 
開發者ID:wso2,項目名稱:product-cep,代碼行數:25,代碼來源:KafkaTestCase.java

示例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();
	}
 
開發者ID:blackberry,項目名稱:Krackle,代碼行數:24,代碼來源:LocalKafkaServer.java

示例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;
}
 
開發者ID:DDTH,項目名稱:ddth-kafka,代碼行數:24,代碼來源:QndEmbeddedServer.java

示例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);
}
 
開發者ID:locationtech,項目名稱:geowave,代碼行數:19,代碼來源:KafkaTestEnvironment.java

示例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");


}
 
開發者ID:Produban,項目名稱:openbus,代碼行數:24,代碼來源:KafkaLocal.java

示例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: ");
}
 
開發者ID:telstra,項目名稱:open-kilda,代碼行數:14,代碼來源:TestUtils.java

示例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();
}
 
開發者ID:telstra,項目名稱:open-kilda,代碼行數:10,代碼來源:Original.java

示例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();
    }
}
 
開發者ID:osswangxining,項目名稱:iotplatform,代碼行數:15,代碼來源:KafkaDemoClient.java

示例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);
    }
}
 
開發者ID:mravi,項目名稱:hbase-connect-kafka,代碼行數:16,代碼來源:KafkaServer.java


注:本文中的kafka.server.KafkaServerStartable.startup方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。