Class KafkaUtils
java.lang.Object
org.springframework.kafka.support.KafkaUtils
Utility methods.
- Since:
- 2.2
- Author:
- Gary Russell
-
Field Summary
Modifier and TypeFieldDescriptionstatic final boolean
True if micrometer is on the class path. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Clear the group id for the consumer bound to this thread.static Duration
determineSendTimeout
(Map<String, Object> producerProps, long buffer, long min) Return the timeout to use when sending records.static String
format
(org.apache.kafka.clients.consumer.ConsumerRecord<?, ?> record) Format theConsumerRecord
for logging; defaulttopic-partition@offset
.static String
format
(org.apache.kafka.clients.producer.ProducerRecord<?, ?> record) static String
Get the group id for the consumer bound to this thread.static boolean
Return true if the method return type isMessage
orCollection<Message<?>>
.static void
setConsumerGroupId
(String groupId) Set the group id for the consumer bound to this thread.static void
setConsumerRecordFormatter
(Function<org.apache.kafka.clients.consumer.ConsumerRecord<?, ?>, String> formatter) Set a formatter for loggingConsumerRecord
s.static void
setLogOnlyMetadata
(boolean onlyMeta) Deprecated, for removal: This API element is subject to removal in a future version.- no longer used.static void
setProducerRecordFormatter
(Function<org.apache.kafka.clients.producer.ProducerRecord<?, ?>, String> formatter) Set a formatter for loggingProducerRecord
s.
-
Field Details
-
MICROMETER_PRESENT
public static final boolean MICROMETER_PRESENTTrue if micrometer is on the class path.
-
-
Method Details
-
returnTypeMessageOrCollectionOf
Return true if the method return type isMessage
orCollection<Message<?>>
.- Parameters:
method
- the method.- Returns:
- true if it returns message(s).
-
setConsumerGroupId
Set the group id for the consumer bound to this thread.- Parameters:
groupId
- the group id.- Since:
- 2.3
-
getConsumerGroupId
Get the group id for the consumer bound to this thread.- Returns:
- the group id.
- Since:
- 2.3
-
clearConsumerGroupId
public static void clearConsumerGroupId()Clear the group id for the consumer bound to this thread.- Since:
- 2.3
-
determineSendTimeout
public static Duration determineSendTimeout(Map<String, Object> producerProps, long buffer, long min) Return the timeout to use when sending records. If theProducerConfig.DELIVERY_TIMEOUT_MS_CONFIG
is not configured, or is not a number or a String that can be parsed as a long, theProducerConfig
default value (plus the buffer) is used.- Parameters:
producerProps
- the producer properties.buffer
- a buffer to add to the configuredProducerConfig.DELIVERY_TIMEOUT_MS_CONFIG
to prevent timing out before the Kafka producer.min
- a minimum value to apply after adding the buffer to the configured timeout.- Returns:
- the timeout to use.
- Since:
- 2.7
-
setLogOnlyMetadata
Deprecated, for removal: This API element is subject to removal in a future version.- no longer used.Set to true to only log record metadata.- Parameters:
onlyMeta
- true to only log record metadata.- Since:
- 2.7.12
-
setConsumerRecordFormatter
public static void setConsumerRecordFormatter(Function<org.apache.kafka.clients.consumer.ConsumerRecord<?, ?>, String> formatter) Set a formatter for loggingConsumerRecord
s.- Parameters:
formatter
- a function to format the record as a String- Since:
- 2.7.12
-
setProducerRecordFormatter
public static void setProducerRecordFormatter(Function<org.apache.kafka.clients.producer.ProducerRecord<?, ?>, String> formatter) Set a formatter for loggingProducerRecord
s.- Parameters:
formatter
- a function to format the record as a String- Since:
- 2.7.12
-
format
Format theConsumerRecord
for logging; defaulttopic-partition@offset
.- Parameters:
record
- the record to format.- Returns:
- the formatted String.
- Since:
- 2.7.12
-
format
- Parameters:
record
- the record to format.- Returns:
- the formatted String.
- Since:
- 2.7.12
-