Search in sources :

Example 1 with EmbeddedZookeeper

use of kafka.zk.EmbeddedZookeeper in project kafka by apache.

the class EmbeddedKafkaCluster method start.

/**
     * Creates and starts a Kafka cluster.
     */
public void start() throws IOException, InterruptedException {
    log.debug("Initiating embedded Kafka cluster startup");
    log.debug("Starting a ZooKeeper instance");
    zookeeper = new EmbeddedZookeeper();
    log.debug("ZooKeeper instance is running at {}", zKConnectString());
    brokerConfig.put(KafkaConfig$.MODULE$.ZkConnectProp(), zKConnectString());
    brokerConfig.put(KafkaConfig$.MODULE$.PortProp(), DEFAULT_BROKER_PORT);
    putIfAbsent(brokerConfig, KafkaConfig$.MODULE$.DeleteTopicEnableProp(), true);
    putIfAbsent(brokerConfig, KafkaConfig$.MODULE$.LogCleanerDedupeBufferSizeProp(), 2 * 1024 * 1024L);
    putIfAbsent(brokerConfig, KafkaConfig$.MODULE$.GroupMinSessionTimeoutMsProp(), 0);
    putIfAbsent(brokerConfig, KafkaConfig$.MODULE$.OffsetsTopicReplicationFactorProp(), (short) 1);
    putIfAbsent(brokerConfig, KafkaConfig$.MODULE$.AutoCreateTopicsEnableProp(), true);
    for (int i = 0; i < brokers.length; i++) {
        brokerConfig.put(KafkaConfig$.MODULE$.BrokerIdProp(), i);
        log.debug("Starting a Kafka instance on port {} ...", brokerConfig.getProperty(KafkaConfig$.MODULE$.PortProp()));
        brokers[i] = new KafkaEmbedded(brokerConfig, time);
        log.debug("Kafka instance is running at {}, connected to ZooKeeper at {}", brokers[i].brokerList(), brokers[i].zookeeperConnect());
    }
}
Also used : EmbeddedZookeeper(kafka.zk.EmbeddedZookeeper)

Example 2 with EmbeddedZookeeper

use of kafka.zk.EmbeddedZookeeper in project storm by apache.

the class KafkaUnit method setUp.

public void setUp() throws IOException {
    // setup ZK
    zkServer = new EmbeddedZookeeper();
    String zkConnect = ZK_HOST + ":" + zkServer.port();
    ZkClient zkClient = new ZkClient(zkConnect, 30000, 30000, ZKStringSerializer$.MODULE$);
    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", String.format("PLAINTEXT://%s:%d", KAFKA_HOST, KAFKA_PORT));
    KafkaConfig config = new KafkaConfig(brokerProps);
    MockTime mock = new MockTime();
    kafkaServer = TestUtils.createServer(config, mock);
    // setup default Producer
    createProducer();
}
Also used : ZkClient(org.I0Itec.zkclient.ZkClient) EmbeddedZookeeper(kafka.zk.EmbeddedZookeeper) Properties(java.util.Properties) MockTime(kafka.utils.MockTime) KafkaConfig(kafka.server.KafkaConfig)

Example 3 with EmbeddedZookeeper

use of kafka.zk.EmbeddedZookeeper 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)

Aggregations

EmbeddedZookeeper (kafka.zk.EmbeddedZookeeper)3 Properties (java.util.Properties)2 KafkaConfig (kafka.server.KafkaConfig)2 MockTime (kafka.utils.MockTime)2 ZkClient (org.I0Itec.zkclient.ZkClient)2 Time (kafka.utils.Time)1 ZkUtils (kafka.utils.ZkUtils)1 PhoenixConsumer (org.apache.phoenix.kafka.consumer.PhoenixConsumer)1 Before (org.junit.Before)1