Class LoggingProducerListener<K,V>
- java.lang.Object
-
- org.springframework.kafka.support.LoggingProducerListener<K,V>
-
- Type Parameters:
K
- the key type.V
- the value type.
- All Implemented Interfaces:
ProducerListener<K,V>
public class LoggingProducerListener<K,V> extends java.lang.Object implements ProducerListener<K,V>
TheProducerListener
that logs exceptions thrown when sending messages.
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_MAX_CONTENT_LOGGED
Default max content logged.protected org.springframework.core.log.LogAccessor
logger
-
Constructor Summary
Constructors Constructor Description LoggingProducerListener()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
onError(org.apache.kafka.clients.producer.ProducerRecord<K,V> record, org.apache.kafka.clients.producer.RecordMetadata recordMetadata, java.lang.Exception exception)
Invoked after an attempt to send a message has failed.void
setIncludeContents(boolean includeContents)
Whether the log message should include the contents (key and payload).void
setMaxContentLogged(int maxContentLogged)
The maximum amount of data to be logged for either key or password.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.springframework.kafka.support.ProducerListener
onSuccess
-
-
-
-
Field Detail
-
DEFAULT_MAX_CONTENT_LOGGED
public static final int DEFAULT_MAX_CONTENT_LOGGED
Default max content logged.- See Also:
- Constant Field Values
-
logger
protected final org.springframework.core.log.LogAccessor logger
-
-
Method Detail
-
setIncludeContents
public void setIncludeContents(boolean includeContents)
Whether the log message should include the contents (key and payload).- Parameters:
includeContents
- true if the contents of the message should be logged
-
setMaxContentLogged
public void setMaxContentLogged(int maxContentLogged)
The maximum amount of data to be logged for either key or password. As message sizes may vary and become fairly large, this allows limiting the amount of data sent to logs. Default 100.- Parameters:
maxContentLogged
- the maximum amount of data being logged.
-
onError
public void onError(org.apache.kafka.clients.producer.ProducerRecord<K,V> record, @Nullable org.apache.kafka.clients.producer.RecordMetadata recordMetadata, java.lang.Exception exception)
Description copied from interface:ProducerListener
Invoked after an attempt to send a message has failed.- Specified by:
onError
in interfaceProducerListener<K,V>
- Parameters:
record
- the failed recordrecordMetadata
- The metadata for the record that was sent (i.e. the partition and offset). If an error occurred, metadata will contain only valid topic and maybe the partition. If the partition is not provided in the ProducerRecord and an error occurs before partition is assigned, then the partition will be set to RecordMetadata.UNKNOWN_PARTITION.exception
- the exception thrown
-
-