Search in sources :

Example 6 with KafkaConfig

use of kafka.server.KafkaConfig in project flink by apache.

the class KafkaTestEnvironmentImpl method getKafkaServer.

/**
	 * Copied from com.github.sakserv.minicluster.KafkaLocalBrokerIntegrationTest (ASL licensed)
	 */
protected KafkaServer getKafkaServer(int brokerId, File tmpFolder) throws Exception {
    Properties kafkaProperties = new Properties();
    // properties have to be Strings
    kafkaProperties.put("advertised.host.name", KAFKA_HOST);
    kafkaProperties.put("broker.id", Integer.toString(brokerId));
    kafkaProperties.put("log.dir", tmpFolder.toString());
    kafkaProperties.put("zookeeper.connect", zookeeperConnectionString);
    kafkaProperties.put("message.max.bytes", String.valueOf(50 * 1024 * 1024));
    kafkaProperties.put("replica.fetch.max.bytes", String.valueOf(50 * 1024 * 1024));
    // for CI stability, increase zookeeper session timeout
    kafkaProperties.put("zookeeper.session.timeout.ms", zkTimeout);
    kafkaProperties.put("zookeeper.connection.timeout.ms", zkTimeout);
    if (additionalServerProperties != null) {
        kafkaProperties.putAll(additionalServerProperties);
    }
    final int numTries = 5;
    for (int i = 1; i <= numTries; i++) {
        int kafkaPort = NetUtils.getAvailablePort();
        kafkaProperties.put("port", Integer.toString(kafkaPort));
        //to support secure kafka cluster
        if (secureMode) {
            LOG.info("Adding Kafka secure configurations");
            kafkaProperties.put("listeners", "SASL_PLAINTEXT://" + KAFKA_HOST + ":" + kafkaPort);
            kafkaProperties.put("advertised.listeners", "SASL_PLAINTEXT://" + KAFKA_HOST + ":" + kafkaPort);
            kafkaProperties.putAll(getSecureProperties());
        }
        KafkaConfig kafkaConfig = new KafkaConfig(kafkaProperties);
        try {
            scala.Option<String> stringNone = scala.Option.apply(null);
            KafkaServer server = new KafkaServer(kafkaConfig, SystemTime$.MODULE$, stringNone);
            server.startup();
            return server;
        } catch (KafkaException e) {
            if (e.getCause() instanceof BindException) {
                // port conflict, retry...
                LOG.info("Port conflict when starting Kafka Broker. Retrying...");
            } else {
                throw e;
            }
        }
    }
    throw new Exception("Could not start Kafka after " + numTries + " retries due to port conflicts.");
}
Also used : KafkaServer(kafka.server.KafkaServer) BindException(java.net.BindException) KafkaException(kafka.common.KafkaException) NetUtils.hostAndPortToUrlString(org.apache.flink.util.NetUtils.hostAndPortToUrlString) Properties(java.util.Properties) KafkaException(kafka.common.KafkaException) BindException(java.net.BindException) KafkaConfig(kafka.server.KafkaConfig)

Example 7 with KafkaConfig

use of kafka.server.KafkaConfig in project ignite by apache.

the class TestKafkaBroker method setupKafkaServer.

/**
     * Sets up test Kafka broker.
     *
     * @throws IOException If failed.
     */
private void setupKafkaServer() throws IOException {
    kafkaCfg = new KafkaConfig(getKafkaConfig());
    kafkaSrv = TestUtils.createServer(kafkaCfg, SystemTime$.MODULE$);
    kafkaSrv.startup();
}
Also used : KafkaConfig(kafka.server.KafkaConfig)

Example 8 with KafkaConfig

use of kafka.server.KafkaConfig in project phoenix by apache.

the class PhoenixConsumerIT method setUp.

@Before
public void setUp() throws IOException, SQLException {
    // setup Zookeeper
    zkServer = new EmbeddedZookeeper();
    String zkConnect = ZKHOST + ":" + zkServer.port();
    zkClient = new ZkClient(zkConnect, 30000, 30000, ZKStringSerializer$.MODULE$);
    ZkUtils zkUtils = ZkUtils.apply(zkClient, false);
    // setup Broker
    Properties brokerProps = new Properties();
    brokerProps.setProperty("zookeeper.connect", zkConnect);
    brokerProps.setProperty("broker.id", "0");
    brokerProps.setProperty("log.dirs", Files.createTempDirectory("kafka-").toAbsolutePath().toString());
    brokerProps.setProperty("listeners", "PLAINTEXT://" + BROKERHOST + ":" + BROKERPORT);
    KafkaConfig config = new KafkaConfig(brokerProps);
    Time mock = new MockTime();
    kafkaServer = TestUtils.createServer(config, mock);
    kafkaServer.startup();
    // create topic
    AdminUtils.createTopic(zkUtils, TOPIC, 1, 1, new Properties());
    pConsumer = new PhoenixConsumer();
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    conn = DriverManager.getConnection(getUrl(), props);
}
Also used : ZkClient(org.I0Itec.zkclient.ZkClient) EmbeddedZookeeper(kafka.zk.EmbeddedZookeeper) PhoenixConsumer(org.apache.phoenix.kafka.consumer.PhoenixConsumer) MockTime(kafka.utils.MockTime) Time(kafka.utils.Time) ZkUtils(kafka.utils.ZkUtils) Properties(java.util.Properties) MockTime(kafka.utils.MockTime) KafkaConfig(kafka.server.KafkaConfig) Before(org.junit.Before)

Example 9 with KafkaConfig

use of kafka.server.KafkaConfig in project heron by twitter.

the class KafkaTestBroker method buildKafkaConfig.

private kafka.server.KafkaConfig buildKafkaConfig(String zookeeperConnectionString) {
    Properties p = new Properties();
    p.setProperty("zookeeper.connect", zookeeperConnectionString);
    p.setProperty("broker.id", "0");
    p.setProperty("port", "" + port);
    p.setProperty("log.dirs", logDir.getAbsolutePath());
    return new KafkaConfig(p);
}
Also used : Properties(java.util.Properties) KafkaConfig(kafka.server.KafkaConfig)

Example 10 with KafkaConfig

use of kafka.server.KafkaConfig in project spark-dataflow by cloudera.

the class EmbeddedKafkaCluster method startBroker.

private static KafkaServer startBroker(Properties props) {
    KafkaServer server = new KafkaServer(new KafkaConfig(props), new SystemTime());
    server.startup();
    return server;
}
Also used : KafkaServer(kafka.server.KafkaServer) KafkaConfig(kafka.server.KafkaConfig)

Aggregations

KafkaConfig (kafka.server.KafkaConfig)15 Properties (java.util.Properties)9 KafkaServer (kafka.server.KafkaServer)8 ZkClient (org.I0Itec.zkclient.ZkClient)4 ArrayList (java.util.ArrayList)3 KafkaMetricsReporter (kafka.metrics.KafkaMetricsReporter)3 File (java.io.File)2 KafkaServerStartable (kafka.server.KafkaServerStartable)2 MockTime (kafka.utils.MockTime)2 Time (kafka.utils.Time)2 EmbeddedZookeeper (kafka.zk.EmbeddedZookeeper)2 TestingServer (org.apache.curator.test.TestingServer)2 Before (org.junit.Before)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Binder (com.google.inject.Binder)1 Module (com.google.inject.Module)1 NamespaceExtractionModule (io.druid.server.lookup.namespace.NamespaceExtractionModule)1 Closeable (java.io.Closeable)1 IOException (java.io.IOException)1 BindException (java.net.BindException)1