Class ListenerUtils
java.lang.Object
org.springframework.kafka.listener.ListenerUtils
Listener utilities.
- Since:
- 2.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic DeserializationExceptionbyteArrayToDeserializationException(org.springframework.core.log.LogAccessor logger, byte[] value) Convert a byte array containing a serializedDeserializationExceptionto theDeserializationException.static org.apache.kafka.clients.consumer.OffsetAndMetadatacreateOffsetAndMetadata(MessageListenerContainer container, long offset) Create a newOffsetAndMetadatausing the given container and offset.static ListenerTypedetermineListenerType(Object listener) Determine the type of the listener.static DeserializationExceptiongetExceptionFromHeader(org.apache.kafka.clients.consumer.ConsumerRecord<?, ?> record, String headerName, org.springframework.core.log.LogAccessor logger) Extract aDeserializationExceptionfrom the supplied header name, if present.static voidstoppableSleep(MessageListenerContainer container, long interval) Sleep for the desired timeout, as long as the container continues to run.static voidunrecoverableBackOff(org.springframework.util.backoff.BackOff backOff, ThreadLocal<org.springframework.util.backoff.BackOffExecution> executions, ThreadLocal<Long> lastIntervals, MessageListenerContainer container) Sleep according to theBackOff; when theBackOffExecutionreturnsBackOffExecution.STOPsleep for the previous backOff.
-
Method Details
-
determineListenerType
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, String headerName, org.springframework.core.log.LogAccessor logger) Extract aDeserializationExceptionfrom 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 serializedDeserializationExceptionto theDeserializationException.- Parameters:
logger- a log accessor to log errors.value- the bytes.- Returns:
- the exception or null if deserialization fails.
- Since:
- 2.8.1
-
unrecoverableBackOff
public static void unrecoverableBackOff(org.springframework.util.backoff.BackOff backOff, ThreadLocal<org.springframework.util.backoff.BackOffExecution> executions, ThreadLocal<Long> lastIntervals, MessageListenerContainer container) throws InterruptedException Sleep according to theBackOff; when theBackOffExecutionreturnsBackOffExecution.STOPsleep for the previous backOff.- Parameters:
backOff- theBackOffto create a newBackOffExecution.executions- a thread local containing theBackOffExecutionfor this thread.lastIntervals- a thread local containing the previousBackOffinterval for this thread.container- the container or parent container.- Throws:
InterruptedException- if the thread is interrupted.- Since:
- 2.7
-
stoppableSleep
public static void stoppableSleep(MessageListenerContainer container, long interval) throws InterruptedException Sleep for the desired timeout, as long as the container continues to run.- Parameters:
container- the container.interval- the timeout.- Throws:
InterruptedException- if the thread is interrupted.- Since:
- 2.7
-
createOffsetAndMetadata
public static org.apache.kafka.clients.consumer.OffsetAndMetadata createOffsetAndMetadata(MessageListenerContainer container, long offset) Create a newOffsetAndMetadatausing the given container and offset.- Parameters:
container- a container.offset- an offset.- Returns:
- an offset and metadata.
- Since:
- 2.8.6
-