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

net.mguenther.kafka.junit.KeyValue Maven / Gradle / Ivy

Go to download

Provides an embedded Kafka cluster consisting of Apache ZooKeeper, Apache Kafka Brokers and Kafka Connect workers in distributed mode along with a rich set of convenient accessors and fault injectors to interact with the embedded Kafka cluster. Supports working against external clusters as well.

There is a newer version: 3.6.0
Show newest version
package net.mguenther.kafka.junit;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import org.apache.kafka.common.header.Header;
import org.apache.kafka.common.header.Headers;
import org.apache.kafka.common.header.internals.RecordHeader;
import org.apache.kafka.common.header.internals.RecordHeaders;

import java.nio.charset.Charset;
import java.util.Optional;

@ToString
@EqualsAndHashCode(of = { "key", "value" })
@RequiredArgsConstructor
public class KeyValue {

    @Getter
    private final K key;

    @Getter
    private final V value;

    @Getter
    private final Headers headers;

    private final KeyValueMetadata metadata;

    public KeyValue(final K key, final V value) {
        this(key, value, new RecordHeaders(), null);
    }

    public KeyValue(final K key, final V value, final Headers headers) {
        this(key, value, headers, null);
    }

    public void addHeader(final String headerName, final String headerValue, final Charset charset) {
        addHeader(headerName, headerValue.getBytes(charset));
    }

    public void addHeader(final String headerName, final byte[] headerValue) {
        final Header header = new RecordHeader(headerName, headerValue);
        headers.add(header);
    }

    public Optional getMetadata() {
        return Optional.ofNullable(metadata);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy