Kafka test clients

Library used for integration tests with embedded kafka.

Лицензия

Лицензия

Категории

Категории

CLI Взаимодействие с пользователем
Группа

Группа

io.github.czeffik
Идентификатор

Идентификатор

kafka-test-clients
Последняя версия

Последняя версия

0.0.2
Дата

Дата

Тип

Тип

pom.sha512
Описание

Описание

Kafka test clients
Library used for integration tests with embedded kafka.
Ссылка на сайт

Ссылка на сайт

https://github.com/Czeffik/kafka-test-clients
Система контроля версий

Система контроля версий

https://github.com/Czeffik/kafka-test-clients

Скачать kafka-test-clients

Зависимости

Библиотека не имеет зависимостей. Это самодостаточное приложение, которое не зависит ни от каких других библиотек.

Модули Проекта

Данный проект не имеет модулей.

Kafka test clients

Kafka consumer sample config

    import org.apache.kafka.clients.consumer.ConsumerConfig;
    import org.apache.kafka.clients.consumer.OffsetResetStrategy;
    import org.apache.kafka.common.serialization.StringDeserializer;
    
    import java.util.Properties;


    <V> KafkaConsumer<String, V> createConsumer(){
        return new KafkaConsumer<>(consumerProperties());
    }

    <V> Properties consumerProperties(){
        final Properties properties = new Properties();
        properties.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "URL_TO_KAFKA_BOOTSTRAP_SERVERS");
        properties.put(ConsumerConfig.GROUP_ID_CONFIG, "TEST_GROUP_ID");
        properties.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, "false");
        properties.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, OffsetResetStrategy.EARLIEST.name().toLowerCase());
        properties.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
        //Without AVRO
        properties.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, YourObjectDeserializer.class);

        //With AVRO - it will depend on which schema registry you are using:
        properties.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, KafkaAvroDeserializer.class);
        properties.put("schema.registry.url", "URL_TO_SCHEMA_REGISTRY");
        properties.put("specific.avro.reader", true);

        return properties;
    }

Kafka producer sample config

    import org.apache.kafka.clients.producer.KafkaProducer;
    import org.apache.kafka.clients.producer.ProducerConfig;
    import org.apache.kafka.common.serialization.StringSerializer;
    
    import java.util.Properties;

    <V> KafkaProducer<String, V> createProducer() {
        return new KafkaProducer<>(producerProperties());
    }

    <V> Properties producerProperties() {
        final Properties properties = new Properties();
        properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "URL_TO_KAFKA_BOOTSTRAP_SERVERS");
        properties.put(ProducerConfig.RETRIES_CONFIG, 0);
        properties.put(ProducerConfig.ENABLE_IDEMPOTENCE_CONFIG, false);
        properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
        properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, YourObjectSeserializer.class);

        //With AVRO - it will depend on which schema registry you are using:
        properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, KafkaAvroSerializer.class);
        properties.put("schema.registry.url", "URL_TO_SCHEMA_REGISTRY");
        properties.put("specific.avro.reader", true);

        return properties;
    }

Версии библиотеки

Версия
0.0.2
0.0.1