/** * Creates and starts a Kafka cluster. */ public void start() throws Exception { log.debug("Initiating embedded Kafka cluster startup"); installJaasConfig(); zookeeper = new ZooKeeperEmbedded(); brokerConfig.put(SimpleAclAuthorizer.ZkUrlProp(), zookeeper.connectString()); // Streams runs multiple consumers, so let's give them all a chance to join. // (Tests run quicker and with a more stable consumer group): brokerConfig.put("group.initial.rebalance.delay.ms", 100); broker = new KafkaEmbedded(effectiveBrokerConfigFrom()); clientConfig.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers()); authorizer.configure(ImmutableMap.of(ZKConfig.ZkConnectProp(), zookeeperConnect())); }
/** * Returns an {@link Authorizer} to make {@link Acl} requests * * @return an {@link Authorizer} to make {@link Acl} requests * * @throws AdminOperationException * if there is an issue creating the authorizer */ public Authorizer getAuthorizer() { if (authorizer == null) { ZKConfig zkConfig = new ZKConfig(new VerifiableProperties(properties)); Map<String, Object> authorizerProps = new HashMap<>(); authorizerProps.put(ZKConfig.ZkConnectProp(), zkConfig.zkConnect()); authorizerProps.put(ZKConfig.ZkConnectionTimeoutMsProp(), zkConfig.zkConnectionTimeoutMs()); authorizerProps.put(ZKConfig.ZkSessionTimeoutMsProp(), zkConfig.zkSessionTimeoutMs()); authorizerProps.put(ZKConfig.ZkSyncTimeMsProp(), zkConfig.zkSyncTimeMs()); try { Authorizer simpleAclAuthorizer = new SimpleAclAuthorizer(); simpleAclAuthorizer.configure(authorizerProps); authorizer = simpleAclAuthorizer; } catch (ZkException e) { throw new AdminOperationException("Unable to create authorizer", e); } } return authorizer; }
private static ZkUtils getZkUtils(Properties properties) { if (properties == null) throw new IllegalArgumentException("properties cannot be null"); Tuple2<ZkClient, ZkConnection> tuple; try { ZKConfig zkConfig = new ZKConfig(new VerifiableProperties(properties)); tuple = ZkUtils.createZkClientAndConnection(zkConfig.zkConnect(), zkConfig.zkSessionTimeoutMs(), zkConfig.zkConnectionTimeoutMs()); } catch (ZkException e) { throw new AdminOperationException("Unable to create admin connection", e); } boolean isSecure = Boolean.valueOf(properties.getProperty(ZOOKEEPER_SECURE, DEFAULT_ZOOKEEPER_SECURE)); return new ZkUtils(tuple._1(), tuple._2(), isSecure); }
/** * Returns properties for either a Kafka producer or consumer. * * @return Combined producer and consumer properties. */ public Properties getProps() { // Combine producer and consumer properties. Properties props = getProducerProps(); props.putAll(getConsumerProps()); // Add zookeeper connect which can be used by KafkaAdminClient or other older clients props.setProperty(ZKConfig.ZkConnectProp(), brokerConfigs.get(0).zkConnect()); return props; }