Class Record<K,V>

java.lang.Object
io.smallrye.reactive.messaging.kafka.Record<K,V>
Type Parameters:
K - the type of the key
V - the type of the value

public class Record<K,V> extends Object
Represents a produced Kafka record, so a pair {key, value}.

This class is used by application willing to configure the written record. The couple key/value is used for, respectively, the record's key and record's value. Instances are used as message's payload.

Both key and value can be null. Instances of this class are immutable.

If the application needs to configure more aspect of the record, use the OutgoingCloudEventMetadata.

If the attached metadata configures the key, the key provided by the record is overidden.

  • Method Details

    • of

      public static <K, V> Record<K,V> of(K key, V value)
      Creates a new record.
      Type Parameters:
      K - the type of the key
      V - the type of the value
      Parameters:
      key - the key, can be null
      value - the value, can be null
    • key

      public K key()
      Returns:
      the key, may be null
    • value

      public V value()
      Returns:
      the value, may be null
    • withKey

      public <T> Record<T,V> withKey(T key)
      Creates a new instance of Record with given key and the value from the current record.
      Type Parameters:
      T - the type of the new key
      Parameters:
      key - the new key, can be null
      Returns:
      the new record
    • withValue

      public <T> Record<K,T> withValue(T value)
      Creates a new instance of Record with the key from the current record and the new value.
      Type Parameters:
      T - the type of the new value
      Parameters:
      value - the new value, can be null
      Returns:
      the new record