Search in sources :

Example 21 with KafkaServer

use of kafka.server.KafkaServer in project atlas by apache.

the class EmbeddedKafkaServer method startKafka.

private void startKafka() throws IOException, URISyntaxException {
    String kafkaValue = properties.getProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG);
    LOG.info("Starting kafka at {}", kafkaValue);
    URL kafkaAddress = getURL(kafkaValue);
    Properties brokerConfig = properties;
    brokerConfig.setProperty("broker.id", "1");
    brokerConfig.setProperty("host.name", kafkaAddress.getHost());
    brokerConfig.setProperty("port", String.valueOf(kafkaAddress.getPort()));
    brokerConfig.setProperty("log.dirs", constructDir("kafka").getAbsolutePath());
    brokerConfig.setProperty("log.flush.interval.messages", String.valueOf(1));
    List<KafkaMetricsReporter> metrics = new ArrayList<>();
    Buffer<KafkaMetricsReporter> metricsReporters = scala.collection.JavaConversions.asScalaBuffer(metrics);
    kafkaServer = new KafkaServer(KafkaConfig.fromProps(brokerConfig), new SystemTime(), Option.apply(this.getClass().getName()), metricsReporters);
    kafkaServer.startup();
    LOG.info("Embedded kafka server started with broker config {}", brokerConfig);
}
Also used : KafkaServer(kafka.server.KafkaServer) ApplicationProperties(org.apache.atlas.ApplicationProperties) URL(java.net.URL) KafkaMetricsReporter(kafka.metrics.KafkaMetricsReporter)

Example 22 with KafkaServer

use of kafka.server.KafkaServer in project wildfly-camel by wildfly-extras.

the class EmbeddedKafkaBroker method startBroker.

private KafkaServer startBroker(Properties props) {
    List<KafkaMetricsReporter> kmrList = new ArrayList<>();
    Buffer<KafkaMetricsReporter> metricsList = scala.collection.JavaConversions.asScalaBuffer(kmrList);
    KafkaServer server = new KafkaServer(new KafkaConfig(props), new SystemTime(), Option.<String>empty(), metricsList);
    server.startup();
    return server;
}
Also used : KafkaServer(kafka.server.KafkaServer) ArrayList(java.util.ArrayList) KafkaMetricsReporter(kafka.metrics.KafkaMetricsReporter) KafkaConfig(kafka.server.KafkaConfig)

Example 23 with KafkaServer

use of kafka.server.KafkaServer in project incubator-gobblin by apache.

the class KafkaClusterTestBase method createKafkaServer.

private KafkaServer createKafkaServer(int brokerId, String _zkConnectString) {
    int _brokerId = brokerId;
    int _kafkaServerPort = TestUtils.findFreePort();
    Properties props = kafka.utils.TestUtils.createBrokerConfig(_brokerId, _zkConnectString, kafka.utils.TestUtils.createBrokerConfig$default$3(), kafka.utils.TestUtils.createBrokerConfig$default$4(), _kafkaServerPort, kafka.utils.TestUtils.createBrokerConfig$default$6(), kafka.utils.TestUtils.createBrokerConfig$default$7(), kafka.utils.TestUtils.createBrokerConfig$default$8(), kafka.utils.TestUtils.createBrokerConfig$default$9(), kafka.utils.TestUtils.createBrokerConfig$default$10(), kafka.utils.TestUtils.createBrokerConfig$default$11(), kafka.utils.TestUtils.createBrokerConfig$default$12(), kafka.utils.TestUtils.createBrokerConfig$default$13(), kafka.utils.TestUtils.createBrokerConfig$default$14());
    KafkaConfig config = new KafkaConfig(props);
    Time mock = new MockTime();
    KafkaServer _kafkaServer = kafka.utils.TestUtils.createServer(config, mock);
    kafkaBrokerPortList.add(_kafkaServerPort);
    return _kafkaServer;
}
Also used : KafkaServer(kafka.server.KafkaServer) MockTime(kafka.utils.MockTime) Time(kafka.utils.Time) Properties(java.util.Properties) MockTime(kafka.utils.MockTime) KafkaConfig(kafka.server.KafkaConfig)

Example 24 with KafkaServer

use of kafka.server.KafkaServer in project incubator-gobblin by apache.

the class KafkaTestBase method provisionTopic.

public void provisionTopic(String topic) {
    if (_topicConsumerMap.containsKey(topic)) {
    // nothing to do: return
    } else {
        // provision topic
        AdminUtils.createTopic(ZkUtils.apply(_kafkaServerSuite.getZkClient(), false), topic, 1, 1, new Properties());
        List<KafkaServer> servers = new ArrayList<>();
        servers.add(_kafkaServerSuite.getKafkaServer());
        kafka.utils.TestUtils.waitUntilMetadataIsPropagated(scala.collection.JavaConversions.asScalaBuffer(servers), topic, 0, 5000);
        KafkaConsumerSuite consumerSuite = new KafkaConsumerSuite(_kafkaServerSuite.getZkConnectString(), topic);
        _topicConsumerMap.put(topic, consumerSuite);
    }
}
Also used : KafkaServer(kafka.server.KafkaServer) ArrayList(java.util.ArrayList) Properties(java.util.Properties)

Example 25 with KafkaServer

use of kafka.server.KafkaServer in project kafka by apache.

the class EmbeddedKafkaCluster method stop.

private void stop(boolean deleteLogDirs, boolean stopZK) {
    try {
        if (producer != null) {
            producer.close();
        }
    } catch (Exception e) {
        log.error("Could not shutdown producer ", e);
        throw new RuntimeException("Could not shutdown producer", e);
    }
    for (KafkaServer broker : brokers) {
        try {
            broker.shutdown();
        } catch (Throwable t) {
            String msg = String.format("Could not shutdown broker at %s", address(broker));
            log.error(msg, t);
            throw new RuntimeException(msg, t);
        }
    }
    if (deleteLogDirs) {
        for (KafkaServer broker : brokers) {
            try {
                log.info("Cleaning up kafka log dirs at {}", broker.config().logDirs());
                CoreUtils.delete(broker.config().logDirs());
            } catch (Throwable t) {
                String msg = String.format("Could not clean up log dirs for broker at %s", address(broker));
                log.error(msg, t);
                throw new RuntimeException(msg, t);
            }
        }
    }
    try {
        if (stopZK) {
            zookeeper.shutdown();
        }
    } catch (Throwable t) {
        String msg = String.format("Could not shutdown zookeeper at %s", zKConnectString());
        log.error(msg, t);
        throw new RuntimeException(msg, t);
    }
}
Also used : KafkaServer(kafka.server.KafkaServer) KafkaException(org.apache.kafka.common.KafkaException) InvalidReplicationFactorException(org.apache.kafka.common.errors.InvalidReplicationFactorException) UnknownTopicOrPartitionException(org.apache.kafka.common.errors.UnknownTopicOrPartitionException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ConnectException(org.apache.kafka.connect.errors.ConnectException)

Aggregations

KafkaServer (kafka.server.KafkaServer)28 Properties (java.util.Properties)16 KafkaConfig (kafka.server.KafkaConfig)13 ArrayList (java.util.ArrayList)9 File (java.io.File)5 KafkaMetricsReporter (kafka.metrics.KafkaMetricsReporter)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Binder (com.google.inject.Binder)2 Module (com.google.inject.Module)2 IOException (java.io.IOException)2 BindException (java.net.BindException)2 URL (java.net.URL)2 KafkaException (kafka.common.KafkaException)2 Time (kafka.utils.Time)2 ZkClient (org.I0Itec.zkclient.ZkClient)2 ApplicationProperties (org.apache.atlas.ApplicationProperties)2 TestingServer (org.apache.curator.test.TestingServer)2 Before (org.junit.Before)2 NamespaceExtractionModule (io.druid.server.lookup.namespace.NamespaceExtractionModule)1 Closeable (java.io.Closeable)1