Class ListenerUtils
- java.lang.Object
-
- org.springframework.kafka.listener.ListenerUtils
-
public final class ListenerUtils extends java.lang.Object
Listener utilities.- Since:
- 2.0
- Author:
- Gary Russell
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static DeserializationException
byteArrayToDeserializationException(org.springframework.core.log.LogAccessor logger, byte[] value)
Convert a byte array containing a serializedDeserializationException
to theDeserializationException
.static ListenerType
determineListenerType(java.lang.Object listener)
Determine the type of the listener.static DeserializationException
getExceptionFromHeader(org.apache.kafka.clients.consumer.ConsumerRecord<?,?> record, java.lang.String headerName, org.springframework.core.log.LogAccessor logger)
Extract aDeserializationException
from the supplied header name, if present.static java.lang.String
recordToString(org.apache.kafka.clients.consumer.ConsumerRecord<?,?> record)
Deprecated.in favor ofKafkaUtils.format(ConsumerRecord)
.static java.lang.String
recordToString(org.apache.kafka.clients.consumer.ConsumerRecord<?,?> record, boolean meta)
Deprecated.in favor ofKafkaUtils.format(ConsumerRecord)
.static void
setLogOnlyMetadata(boolean onlyMeta)
Deprecated.in favor ofKafkaUtils.format(ConsumerRecord)
.static void
stoppableSleep(MessageListenerContainer container, long interval)
Sleep for the desired timeout, as long as the container continues to run.static void
unrecoverableBackOff(org.springframework.util.backoff.BackOff backOff, java.lang.ThreadLocal<org.springframework.util.backoff.BackOffExecution> executions, java.lang.ThreadLocal<java.lang.Long> lastIntervals)
Deprecated.since 2.7 in favor ofunrecoverableBackOff(BackOff, ThreadLocal, ThreadLocal, MessageListenerContainer)
.static void
unrecoverableBackOff(org.springframework.util.backoff.BackOff backOff, java.lang.ThreadLocal<org.springframework.util.backoff.BackOffExecution> executions, java.lang.ThreadLocal<java.lang.Long> lastIntervals, MessageListenerContainer container)
Sleep according to theBackOff
; when theBackOffExecution
returnsBackOffExecution.STOP
sleep for the previous backOff.
-
-
-
Method Detail
-
determineListenerType
public static ListenerType determineListenerType(java.lang.Object listener)
Determine the type of the listener.- Parameters:
listener
- the listener.- Returns:
- the
ListenerType
.
-
getExceptionFromHeader
@Nullable public static DeserializationException getExceptionFromHeader(org.apache.kafka.clients.consumer.ConsumerRecord<?,?> record, java.lang.String headerName, org.springframework.core.log.LogAccessor logger)
Extract aDeserializationException
from the supplied header name, if present.- Parameters:
record
- the consumer record.headerName
- the header name.logger
- the logger for logging errors.- Returns:
- the exception or null.
- Since:
- 2.3
-
byteArrayToDeserializationException
@Nullable public static DeserializationException byteArrayToDeserializationException(org.springframework.core.log.LogAccessor logger, byte[] value)
Convert a byte array containing a serializedDeserializationException
to theDeserializationException
.- Parameters:
logger
- a log accessor to log errors.value
- the bytes.- Returns:
- the exception or null if deserialization fails.
- Since:
- 2.8.1
-
setLogOnlyMetadata
@Deprecated public static void setLogOnlyMetadata(boolean onlyMeta)
Deprecated.in favor ofKafkaUtils.format(ConsumerRecord)
.Set to true to only log record metadata.- Parameters:
onlyMeta
- true to only log record metadata.- Since:
- 2.2.14
- See Also:
recordToString(ConsumerRecord)
-
recordToString
@Deprecated public static java.lang.String recordToString(org.apache.kafka.clients.consumer.ConsumerRecord<?,?> record)
Deprecated.in favor ofKafkaUtils.format(ConsumerRecord)
.Return theConsumerRecord
as a String; eithertoString()
ortopic-partition@offset
.- Parameters:
record
- the record.- Returns:
- the rendered record.
- Since:
- 2.2.14
- See Also:
setLogOnlyMetadata(boolean)
-
recordToString
@Deprecated public static java.lang.String recordToString(org.apache.kafka.clients.consumer.ConsumerRecord<?,?> record, boolean meta)
Deprecated.in favor ofKafkaUtils.format(ConsumerRecord)
.Return theConsumerRecord
as a String; eithertoString()
ortopic-partition@offset
.- Parameters:
record
- the record.meta
- true to log just the metadata.- Returns:
- the rendered record.
- Since:
- 2.5.4
-
unrecoverableBackOff
@Deprecated public static void unrecoverableBackOff(org.springframework.util.backoff.BackOff backOff, java.lang.ThreadLocal<org.springframework.util.backoff.BackOffExecution> executions, java.lang.ThreadLocal<java.lang.Long> lastIntervals)
Deprecated.since 2.7 in favor ofunrecoverableBackOff(BackOff, ThreadLocal, ThreadLocal, MessageListenerContainer)
.Sleep according to theBackOff
; when theBackOffExecution
returnsBackOffExecution.STOP
sleep for the previous backOff.- Parameters:
backOff
- theBackOff
to create a newBackOffExecution
.executions
- a thread local containing theBackOffExecution
for this thread.lastIntervals
- a thread local containing the previousBackOff
interval for this thread.- Since:
- 2.3.12
-
unrecoverableBackOff
public static void unrecoverableBackOff(org.springframework.util.backoff.BackOff backOff, java.lang.ThreadLocal<org.springframework.util.backoff.BackOffExecution> executions, java.lang.ThreadLocal<java.lang.Long> lastIntervals, MessageListenerContainer container) throws java.lang.InterruptedException
Sleep according to theBackOff
; when theBackOffExecution
returnsBackOffExecution.STOP
sleep for the previous backOff.- Parameters:
backOff
- theBackOff
to create a newBackOffExecution
.executions
- a thread local containing theBackOffExecution
for this thread.lastIntervals
- a thread local containing the previousBackOff
interval for this thread.container
- the container or parent container.- Throws:
java.lang.InterruptedException
- if the thread is interrupted.- Since:
- 2.7
-
stoppableSleep
public static void stoppableSleep(MessageListenerContainer container, long interval) throws java.lang.InterruptedException
Sleep for the desired timeout, as long as the container continues to run.- Parameters:
container
- the container.interval
- the timeout.- Throws:
java.lang.InterruptedException
- if the thread is interrupted.- Since:
- 2.7
-
-