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

com.icthh.xm.commons.topic.service.KafkaTemplateService Maven / Gradle / Ivy

There is a newer version: 4.0.17
Show newest version
package com.icthh.xm.commons.topic.service;

import com.icthh.xm.commons.logging.LoggingAspectConfig;
import lombok.RequiredArgsConstructor;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.support.SendResult;
import org.springframework.stereotype.Service;
import java.util.concurrent.CompletableFuture;

@Service
@RequiredArgsConstructor
public class KafkaTemplateService {

    private final KafkaTemplate kafkaTemplate;

    /**
     * Send the data to the provided topic with no key or partition.
     *
     * @param topic the topic.
     * @param data  The data.
     * @return a Future for the {@link SendResult}.
     **/
    @LoggingAspectConfig(inputExcludeParams = "data", resultDetails = false)
    public CompletableFuture> send(String topic, String data) {
        return kafkaTemplate.send(topic, data);
    }

    /**
     * Send the data to the provided topic with the provided key and partition.
     *
     * @param topic     the topic.
     * @param partition the partition.
     * @param key       the key.
     * @param data      the data.
     * @return a Future for the {@link SendResult}.
     */
    @LoggingAspectConfig(inputExcludeParams = "data", resultDetails = false)
    public CompletableFuture> send(String topic,
                                                             Integer partition,
                                                             String key,
                                                             String data) {
        return kafkaTemplate.send(topic, partition, key, data);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy