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.-
Methodenübersicht
Modifizierer und TypMethodeBeschreibungdefault StringgetKeyOrNull(Object payload) static <X> CompactionKeyExtractorA type-safe compaction key extractor.static CompactionKeyExtractorAn 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 CompactionKeyExtractorNon-type safe key extractor, returning an Optional.
-
Methodendetails
-
getKeyOrNull
-
tryGetKeyFor
-
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 oftypeand input type ofextractorFunction.- 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 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.- 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 returnOptional.empty()if this extractor can't handle the input object, otherwise the actual key.- Gibt zurück:
- a key extractor object.
-
ofNullable
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 returnnullif this extractor can't handle the input object, otherwise the actual key.- Gibt zurück:
- a key extractor object.
-
of
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 returnnull.- Gibt zurück:
- a key extractor object.
-