All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.micronaut.configuration.kafka.config.AbstractKafkaConsumerConfiguration Maven / Gradle / Ivy

There is a newer version: 5.7.0
Show newest version
/*
 * Copyright 2017-2020 original authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.micronaut.configuration.kafka.config;

import org.apache.kafka.common.serialization.Deserializer;

import io.micronaut.core.annotation.Nullable;
import java.util.Optional;
import java.util.Properties;

/**
 * Abstract Configuration for Apache Kafka Consumer. See https://kafka.apache.org/documentation/#consumerconfigs
 *
 * @param  The key deserializer type
 * @param  The value deserializer type
 * @author Graeme Rocher
 * @since 1.0
 */
public abstract class AbstractKafkaConsumerConfiguration extends AbstractKafkaConfiguration {

    private Deserializer keyDeserializer;
    private Deserializer valueDeserializer;

    /**
     * Constructs a new instance.
     *
     * @param config The config to use
     */
    @SuppressWarnings("WeakerAccess")
    protected AbstractKafkaConsumerConfiguration(Properties config) {
        super(config);
    }

    /**
     * @return The default key {@link Deserializer}
     */
    @SuppressWarnings("WeakerAccess")
    public Optional> getKeyDeserializer() {
        return Optional.ofNullable(keyDeserializer);
    }

    /**
     * Sets the key deserializer.
     *
     * @param keyDeserializer The key serializer
     */
    public void setKeyDeserializer(@Nullable Deserializer keyDeserializer) {
        this.keyDeserializer = keyDeserializer;
    }

    /**
     * @return The default value {@link Deserializer}
     */
    @SuppressWarnings("WeakerAccess")
    public Optional> getValueDeserializer() {
        return Optional.ofNullable(valueDeserializer);
    }

    /**
     * Sets the default value deserializer.
     *
     * @param valueDeserializer The value deserializer
     */
    public void setValueDeserializer(@Nullable Deserializer valueDeserializer) {
        this.valueDeserializer = valueDeserializer;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy