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);
}
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;
}
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;
}
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);
}
}
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);
}
}
Aggregations