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

io.smallrye.reactive.messaging.kafka.SendingKafkaMessage Maven / Gradle / Ivy

There is a newer version: 4.25.0
Show newest version
package io.smallrye.reactive.messaging.kafka;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.function.Supplier;

public class SendingKafkaMessage implements KafkaMessage {

    private final String topic;
    private final K key;
    private final T value;
    private final Integer partition;
    private final Long timestamp;
    private final MessageHeaders headers;
    private final Supplier> ack;

    public SendingKafkaMessage(String topic, K key, T value, Long timestamp, Integer partition, MessageHeaders headers,
            Supplier> ack) {
        this.topic = topic;
        this.key = key;
        this.value = value;
        this.partition = partition;
        this.timestamp = timestamp;
        this.headers = headers;
        this.ack = ack;
    }

    @Override
    public CompletionStage ack() {
        if (ack == null) {
            return CompletableFuture.completedFuture(null);
        } else {
            return ack.get();
        }
    }

    @Override
    public T getPayload() {
        return this.value;
    }

    @Override
    public K getKey() {
        return this.key;
    }

    @Override
    public String getTopic() {
        return this.topic;
    }

    @Override
    public Long getTimestamp() {
        return timestamp;
    }

    @Override
    public MessageHeaders getHeaders() {
        return headers;
    }

    @Override
    public Supplier> getAckSupplier() {
        return ack;
    }

    @Override
    public Integer getPartition() {
        if (partition == null || partition < 0) {
            return null;
        }
        return partition;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy