Schnittstelle CompactionKeyExtractor


public interface CompactionKeyExtractor
This interface defines a way of extracting a compaction key from an object which is sent as a payload in a compacted event type. In most cases, for each compacted event type exactly one such object will be made known to the producer, and you can define it using of(String, Class, Function), passing a method reference or a lambda. For special occasions (e.g. where objects of different classes are used as payloads for the same event type) also multiple extractors for the same event type are supported – in this case any which returns a non-empty optional will be used.
  • Methodendetails

    • getKeyOrNull

      default String getKeyOrNull(Object payload)
    • tryGetKeyFor

      Optional<String> tryGetKeyFor(Object o)
    • getEventType

      String getEventType()
    • of

      static <X> CompactionKeyExtractor of(String eventType, Class<X> type, Function<X,String> extractorFunction)
      A type-safe compaction key extractor. This will be the one to be used by most applications.
      Typparameter:
      X - the type of type and input type of extractorFunction.
      Parameter:
      eventType - Indicates the event type. Only events sent to this event type will be considered.
      type - A Java type for payload objects. Only payload objects where type.isInstance(payload) will be considered at all.
      extractorFunction - A function extracting a compaction key from a payload object. This will commonly be given as a method reference or lambda.
      Gibt zurück:
      A compaction key extractor, to be defined as a spring bean (if using the spring-boot starter) or passed manually to the event log writer implementation (if using nakadi-producer directly). (This should not return null.)
    • ofOptional

      static CompactionKeyExtractor ofOptional(String eventType, Function<Object,Optional<String>> extractor)
      Non-type safe key extractor, returning an Optional.
      Parameter:
      eventType - The event type for which this extractor is intended.
      extractor - The extractor function. It is supposed to return Optional.empty() if this extractor can't handle the input object, otherwise the actual key.
      Gibt zurück:
      a key extractor object.
    • ofNullable

      static CompactionKeyExtractor ofNullable(String eventType, Function<Object,String> extractor)
      Non-type safe key extractor, returning null for unknown objects.
      Parameter:
      eventType - The event type for which this extractor is intended.
      extractor - The extractor function. It is supposed to return null if this extractor can't handle the input object, otherwise the actual key.
      Gibt zurück:
      a key extractor object.
    • of

      static CompactionKeyExtractor of(String eventType, Function<Object,String> extractor)
      An universal key extractor, capable of handling all objects.
      Parameter:
      eventType - The event type for which this extractor is intended.
      extractor - The extractor function. It is not allowed to return null.
      Gibt zurück:
      a key extractor object.