public class HeaderUtils extends Object
Headers
. Mostly for internal use.Modifier and Type | Method and Description |
---|---|
static void |
addHeader(org.apache.kafka.common.header.Headers target,
String key,
Object value)
Creates a new
RecordHeader based on key and
value and adds it to target . |
static Long |
asLong(byte[] value)
Converts bytes to long.
|
static String |
asString(byte[] value)
Converts bytes to String.
|
static BiFunction<String,Object,org.apache.kafka.common.header.internals.RecordHeader> |
byteMapper()
Handles
value conversion to bytes. |
static Map<String,Object> |
extractAxonMetadata(org.apache.kafka.common.header.Headers target)
Extract axon metadata(if any) attached with
Headers . |
static String |
extractKey(String metadataKey)
Extracts actual key name used to send Axon metadata.
|
static String |
generateMetadataKey(String key)
Generates
key , used to identify Axon metadata in RecordHeader . |
static Set<String> |
keys(org.apache.kafka.common.header.Headers headers)
Extract keys from
Headers . |
static byte[] |
toBytes(Number value)
Converts primitive arithmetic types to byte array.
|
static org.apache.kafka.common.header.Headers |
toHeaders(EventMessage<?> eventMessage,
SerializedObject<byte[]> serializedObject,
BiFunction<String,Object,org.apache.kafka.common.header.internals.RecordHeader> headerValueMapper)
|
static byte[] |
value(org.apache.kafka.common.header.Headers headers,
String key)
Return the
value stored under a given key inside the Headers . |
static Long |
valueAsLong(org.apache.kafka.common.header.Headers headers,
String key)
Return Long representation of the
value stored under a given key inside the Headers . |
static String |
valueAsString(org.apache.kafka.common.header.Headers headers,
String key)
Return String representation of the
value stored under a given key inside the Headers . |
static String |
valueAsString(org.apache.kafka.common.header.Headers headers,
String key,
String defaultValue)
Return String representation of the
value stored under a given key inside the
Headers . |
public static Long asLong(byte[] value)
value
- representing long.public static Long valueAsLong(org.apache.kafka.common.header.Headers headers, String key)
value
stored under a given key
inside the Headers
. In case of missing entry null
is returned.headers
- the Kafka headers.key
- the expected key.public static String asString(byte[] value)
value
- bytes representing String
.public static String valueAsString(org.apache.kafka.common.header.Headers headers, String key)
value
stored under a given key
inside the Headers
. In case of missing entry null
is returned.headers
- the Kafka headers.key
- the expected key.public static String valueAsString(org.apache.kafka.common.header.Headers headers, String key, String defaultValue)
value
stored under a given key
inside the
Headers
. In case of missing entry defaultValue
is returned.headers
- the Kafka headers.key
- the expected key.defaultValue
- the value when key is missing.public static byte[] value(org.apache.kafka.common.header.Headers headers, String key)
value
stored under a given key
inside the Headers
. In case of missing entry null
is returned.headers
- the Kafka headers.key
- the expected key.public static byte[] toBytes(Number value)
value
- the number.public static void addHeader(org.apache.kafka.common.header.Headers target, String key, Object value)
RecordHeader
based on key
and
value
and adds it to target
. The value is converted to bytes and follows this logic:
Instant.toEpochMilli()
toBytes(java.lang.Number)
String.toString()
null
target
- the Kafka headers.key
- the key you want to add in the header.value
- the value you want to store in the header.public static Set<String> keys(org.apache.kafka.common.header.Headers headers)
Headers
.headers
- the Kafka header.public static String generateMetadataKey(String key)
key
, used to identify Axon metadata in RecordHeader
.key
- the actual key.public static String extractKey(String metadataKey)
"axon-metadata-foo"
will extract foo
metadataKey
- the generated metadata key.public static Map<String,Object> extractAxonMetadata(org.apache.kafka.common.header.Headers target)
Headers
.target
- kafka header.public static org.apache.kafka.common.header.Headers toHeaders(EventMessage<?> eventMessage, SerializedObject<byte[]> serializedObject, BiFunction<String,Object,org.apache.kafka.common.header.internals.RecordHeader> headerValueMapper)
eventMessage
- provides event data.serializedObject
- payload.headerValueMapper
- function for converting value
to bytes. Since RecordHeader
can handle only bytes this function needs to define the logic how to
convert a given value to bytes. See byteMapper()
for sample
implementation.public static BiFunction<String,Object,org.apache.kafka.common.header.internals.RecordHeader> byteMapper()
value
conversion to bytes.Copyright © 2010–2018. All rights reserved.