kafka.utils.ZKConfig Java Examples

The following examples show how to use kafka.utils.ZKConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KafkaAdminClient.java    From common-kafka with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a Kafka admin client with the given properties
 *
 * @param properties
 *      the properties to use to connect to the Kafka cluster
 * @throws IllegalArgumentException
 * <ul>
 *     <li>if properties is {@code null}</li>
 *     <li>if the property for {@link ZKConfig#ZkConnectProp()} is not set</li>
 *     <li>if the property for {@link #OPERATION_TIMEOUT_MS} is not a number or less than zero</li>
 *     <li>if the property for {@link #OPERATION_SLEEP_MS} is not a number or less than zero</li>
 * </ul>
 */
public KafkaAdminClient(Properties properties) {
    if (properties == null)
        throw new IllegalArgumentException("properties cannot be null");

    if (properties.getProperty(ZKConfig.ZkConnectProp()) == null)
        throw new IllegalArgumentException("missing required property: " + ZKConfig.ZkConnectProp());

    this.properties = properties;
    this.operationTimeout = parseLong(properties, OPERATION_TIMEOUT_MS, DEFAULT_OPERATION_TIMEOUT_MS);
    this.operationSleep = parseLong(properties, OPERATION_SLEEP_MS, DEFAULT_OPERATION_SLEEP_MS);

    if (operationTimeout < 0)
        throw new IllegalArgumentException("operationTimeout cannot be < 0");

    if (operationSleep < 0)
        throw new IllegalArgumentException("operationSleep cannot be < 0");
}
 
Example #2
Source File: KafkaAdminClient.java    From common-kafka with Apache License 2.0 6 votes vote down vote up
/**
 * 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 | ZooKeeperClientException e) {
            throw new AdminOperationException("Unable to create authorizer", e);
        }
    }

    return authorizer;
}
 
Example #3
Source File: EmbeddedSingleNodeKafkaCluster.java    From ksql-fork-with-deep-learning-function with Apache License 2.0 5 votes vote down vote up
/**
 * Creates and starts a Kafka cluster.
 */
public void start() throws Exception {
  log.debug("Initiating embedded Kafka cluster startup");

  zookeeper = new ZooKeeperEmbedded();
  broker = new KafkaEmbedded(effectiveBrokerConfigFrom());
  clientConfig.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers());
  brokerConfig.put(SimpleAclAuthorizer.ZkUrlProp(), zookeeper.connectString());
  authorizer.configure(ImmutableMap.of(ZKConfig.ZkConnectProp(), zookeeperConnect()));
}
 
Example #4
Source File: KafkaBrokerTestHarness.java    From common-kafka with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}