Interface CompactionKeyExtractor
-
public interface CompactionKeyExtractorThis 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 usingof(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.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description StringgetEventType()default StringgetKeyOrNull(Object payload)static <X> CompactionKeyExtractorof(String eventType, Class<X> type, Function<X,String> extractorFunction)A type-safe compaction key extractor.static CompactionKeyExtractorof(String eventType, Function<Object,String> extractor)An universal key extractor, capable of handling all objects.static CompactionKeyExtractorofNullable(String eventType, Function<Object,String> extractor)Non-type safe key extractor, returning null for unknown objects.static CompactionKeyExtractorofOptional(String eventType, Function<Object,Optional<String>> extractor)Non-type safe key extractor, returning an Optional.Optional<String>tryGetKeyFor(Object o)
-
-
-
Method Detail
-
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.- Type Parameters:
X- the type oftypeand input type ofextractorFunction.- Parameters:
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 wheretype.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.- Returns:
- 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.- Parameters:
eventType- The event type for which this extractor is intended.extractor- The extractor function. It is supposed to returnOptional.empty()if this extractor can't handle the input object, otherwise the actual key.- Returns:
- a key extractor object.
-
ofNullable
static CompactionKeyExtractor ofNullable(String eventType, Function<Object,String> extractor)
Non-type safe key extractor, returning null for unknown objects.- Parameters:
eventType- The event type for which this extractor is intended.extractor- The extractor function. It is supposed to returnnullif this extractor can't handle the input object, otherwise the actual key.- Returns:
- a key extractor object.
-
of
static CompactionKeyExtractor of(String eventType, Function<Object,String> extractor)
An universal key extractor, capable of handling all objects.- Parameters:
eventType- The event type for which this extractor is intended.extractor- The extractor function. It is not allowed to returnnull.- Returns:
- a key extractor object.
-
-