Search in sources :

Example 1 with AdminClientConfig

use of org.apache.kafka.clients.admin.AdminClientConfig in project apache-kafka-on-k8s by banzaicloud.

the class StreamsConfig method getConsumerConfigs.

/**
 * Get the configs to the {@link KafkaConsumer consumer}.
 * Properties using the prefix {@link #CONSUMER_PREFIX} will be used in favor over their non-prefixed versions
 * except in the case of {@link ConsumerConfig#BOOTSTRAP_SERVERS_CONFIG} where we always use the non-prefixed
 * version as we only support reading/writing from/to the same Kafka Cluster.
 *
 * @param groupId      consumer groupId
 * @param clientId     clientId
 * @return Map of the consumer configuration.
 */
public Map<String, Object> getConsumerConfigs(final String groupId, final String clientId) {
    final Map<String, Object> consumerProps = getCommonConsumerConfigs();
    // add client id with stream client id prefix, and group id
    consumerProps.put(APPLICATION_ID_CONFIG, groupId);
    consumerProps.put(ConsumerConfig.GROUP_ID_CONFIG, groupId);
    consumerProps.put(CommonClientConfigs.CLIENT_ID_CONFIG, clientId + "-consumer");
    // add configs required for stream partition assignor
    consumerProps.put(REPLICATION_FACTOR_CONFIG, getInt(REPLICATION_FACTOR_CONFIG));
    consumerProps.put(APPLICATION_SERVER_CONFIG, getString(APPLICATION_SERVER_CONFIG));
    consumerProps.put(NUM_STANDBY_REPLICAS_CONFIG, getInt(NUM_STANDBY_REPLICAS_CONFIG));
    consumerProps.put(ConsumerConfig.PARTITION_ASSIGNMENT_STRATEGY_CONFIG, StreamsPartitionAssignor.class.getName());
    consumerProps.put(WINDOW_STORE_CHANGE_LOG_ADDITIONAL_RETENTION_MS_CONFIG, getLong(WINDOW_STORE_CHANGE_LOG_ADDITIONAL_RETENTION_MS_CONFIG));
    // add admin retries configs for creating topics
    final AdminClientConfig adminClientDefaultConfig = new AdminClientConfig(getClientPropsWithPrefix(ADMIN_CLIENT_PREFIX, AdminClientConfig.configNames()));
    consumerProps.put(adminClientPrefix(AdminClientConfig.RETRIES_CONFIG), adminClientDefaultConfig.getInt(AdminClientConfig.RETRIES_CONFIG));
    // verify that producer batch config is no larger than segment size, then add topic configs required for creating topics
    final Map<String, Object> topicProps = originalsWithPrefix(TOPIC_PREFIX, false);
    if (topicProps.containsKey(topicPrefix(TopicConfig.SEGMENT_INDEX_BYTES_CONFIG))) {
        final int segmentSize = Integer.parseInt(topicProps.get(topicPrefix(TopicConfig.SEGMENT_INDEX_BYTES_CONFIG)).toString());
        final Map<String, Object> producerProps = getClientPropsWithPrefix(PRODUCER_PREFIX, ProducerConfig.configNames());
        final int batchSize;
        if (producerProps.containsKey(ProducerConfig.BATCH_SIZE_CONFIG)) {
            batchSize = Integer.parseInt(producerProps.get(ProducerConfig.BATCH_SIZE_CONFIG).toString());
        } else {
            final ProducerConfig producerDefaultConfig = new ProducerConfig(new Properties());
            batchSize = producerDefaultConfig.getInt(ProducerConfig.BATCH_SIZE_CONFIG);
        }
        if (segmentSize < batchSize) {
            throw new IllegalArgumentException(String.format("Specified topic segment size %d is is smaller than the configured producer batch size %d, this will cause produced batch not able to be appended to the topic", segmentSize, batchSize));
        }
    }
    consumerProps.putAll(topicProps);
    return consumerProps;
}
Also used : AdminClientConfig(org.apache.kafka.clients.admin.AdminClientConfig) StreamsPartitionAssignor(org.apache.kafka.streams.processor.internals.StreamsPartitionAssignor) ProducerConfig(org.apache.kafka.clients.producer.ProducerConfig) Properties(java.util.Properties)

Aggregations

Properties (java.util.Properties)1 AdminClientConfig (org.apache.kafka.clients.admin.AdminClientConfig)1 ProducerConfig (org.apache.kafka.clients.producer.ProducerConfig)1 StreamsPartitionAssignor (org.apache.kafka.streams.processor.internals.StreamsPartitionAssignor)1