|
16 | 16 |
|
17 | 17 | package org.springframework.kafka.support;
|
18 | 18 |
|
| 19 | +import org.apache.kafka.clients.producer.ProducerRecord; |
19 | 20 | import org.apache.kafka.clients.producer.RecordMetadata;
|
20 | 21 |
|
21 | 22 | /**
|
|
30 | 31 | *
|
31 | 32 | * @author Marius Bogoevici
|
32 | 33 | * @author Gary Russell
|
| 34 | + * @author Endika Gutiérrez |
33 | 35 | *
|
34 | 36 | * @see org.apache.kafka.clients.producer.Callback
|
35 | 37 | */
|
36 | 38 | public interface ProducerListener<K, V> {
|
37 | 39 |
|
38 | 40 | /**
|
39 | 41 | * Invoked after the successful send of a message (that is, after it has been acknowledged by the broker).
|
| 42 | + * @param producerRecord the actual sent record |
| 43 | + * @param recordMetadata the result of the successful send operation |
| 44 | + */ |
| 45 | + default void onSuccess(ProducerRecord<K, V> producerRecord, RecordMetadata recordMetadata) { |
| 46 | + onSuccess(producerRecord.topic(), producerRecord.partition(), |
| 47 | + producerRecord.key(), producerRecord.value(), recordMetadata); |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * Invoked after the successful send of a message (that is, after it has been acknowledged by the broker). |
| 52 | + * If the method receiving the ProducerRecord is overridden, this method won't be called |
40 | 53 | * @param topic the destination topic
|
41 | 54 | * @param partition the destination partition (could be null)
|
42 | 55 | * @param key the key of the outbound message
|
43 | 56 | * @param value the payload of the outbound message
|
44 | 57 | * @param recordMetadata the result of the successful send operation
|
45 | 58 | */
|
46 |
| - void onSuccess(String topic, Integer partition, K key, V value, RecordMetadata recordMetadata); |
| 59 | + default void onSuccess(String topic, Integer partition, K key, V value, RecordMetadata recordMetadata) { |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * Invoked after an attempt to send a message has failed. |
| 64 | + * @param producerRecord the failed record |
| 65 | + * @param exception the exception thrown |
| 66 | + */ |
| 67 | + default void onError(ProducerRecord<K, V> producerRecord, Exception exception) { |
| 68 | + onError(producerRecord.topic(), producerRecord.partition(), |
| 69 | + producerRecord.key(), producerRecord.value(), exception); |
| 70 | + } |
47 | 71 |
|
48 | 72 | /**
|
49 | 73 | * Invoked after an attempt to send a message has failed.
|
| 74 | + * If the method receiving the ProducerRecord is overridden, this method won't be called |
50 | 75 | * @param topic the destination topic
|
51 | 76 | * @param partition the destination partition (could be null)
|
52 | 77 | * @param key the key of the outbound message
|
53 | 78 | * @param value the payload of the outbound message
|
54 | 79 | * @param exception the exception thrown
|
55 | 80 | */
|
56 |
| - void onError(String topic, Integer partition, K key, V value, Exception exception); |
| 81 | + default void onError(String topic, Integer partition, K key, V value, Exception exception) { |
| 82 | + } |
57 | 83 |
|
58 | 84 | /**
|
59 | 85 | * Return true if this listener is interested in success as well as failure.
|
| 86 | + * @deprecated the result of this method will be ignored. |
60 | 87 | * @return true to express interest in successful sends.
|
61 | 88 | */
|
62 |
| - boolean isInterestedInSuccess(); |
| 89 | + @Deprecated |
| 90 | + default boolean isInterestedInSuccess() { |
| 91 | + return false; |
| 92 | + } |
63 | 93 |
|
64 | 94 | }
|
0 commit comments