@@ -69,16 +69,6 @@ public FailedBatchProcessor(@Nullable BiConsumer<ConsumerRecord<?, ?>, Exception
69
69
this (recoverer , backOff , null , fallbackHandler );
70
70
}
71
71
72
- /**
73
- * Return the fallback batch error handler.
74
- * @return the handler.
75
- * @since 2.8.8
76
- */
77
- protected CommonErrorHandler getFallbackBatchHandler () {
78
- return this .fallbackBatchHandler ;
79
- }
80
-
81
-
82
72
/**
83
73
* Construct an instance with the provided properties.
84
74
* @param recoverer the recoverer.
@@ -94,6 +84,15 @@ public FailedBatchProcessor(@Nullable BiConsumer<ConsumerRecord<?, ?>, Exception
94
84
this .fallbackBatchHandler = fallbackHandler ;
95
85
}
96
86
87
+ /**
88
+ * Return the fallback batch error handler.
89
+ * @return the handler.
90
+ * @since 2.8.8
91
+ */
92
+ protected CommonErrorHandler getFallbackBatchHandler () {
93
+ return this .fallbackBatchHandler ;
94
+ }
95
+
97
96
protected void doHandle (Exception thrownException , ConsumerRecords <?, ?> data , Consumer <?, ?> consumer ,
98
97
MessageListenerContainer container , Runnable invokeListener ) {
99
98
@@ -105,17 +104,18 @@ protected <K, V> ConsumerRecords<K, V> handle(Exception thrownException, Consume
105
104
106
105
BatchListenerFailedException batchListenerFailedException = getBatchListenerFailedException (thrownException );
107
106
if (batchListenerFailedException == null ) {
108
- this .logger .debug (thrownException , "Expected a BatchListenerFailedException; re-seeking batch" );
109
- this . fallbackBatchHandler . handleBatch (thrownException , data , consumer , container , invokeListener );
107
+ this .logger .debug (thrownException , "Expected a BatchListenerFailedException; re-delivering full batch" );
108
+ fallback (thrownException , data , consumer , container , invokeListener );
110
109
}
111
110
else {
111
+ getRetryListeners ().forEach (listener -> listener .failedDelivery (data , thrownException , 1 ));
112
112
ConsumerRecord <?, ?> record = batchListenerFailedException .getRecord ();
113
113
int index = record != null ? findIndex (data , record ) : batchListenerFailedException .getIndex ();
114
114
if (index < 0 || index >= data .count ()) {
115
115
this .logger .warn (batchListenerFailedException , () ->
116
116
String .format ("Record not found in batch: %s-%d@%d; re-seeking batch" ,
117
117
record .topic (), record .partition (), record .offset ()));
118
- this . fallbackBatchHandler . handleBatch (thrownException , data , consumer , container , invokeListener );
118
+ fallback (thrownException , data , consumer , container , invokeListener );
119
119
}
120
120
else {
121
121
return seekOrRecover (thrownException , data , consumer , container , index );
@@ -124,6 +124,18 @@ protected <K, V> ConsumerRecords<K, V> handle(Exception thrownException, Consume
124
124
return ConsumerRecords .empty ();
125
125
}
126
126
127
+ private void fallback (Exception thrownException , ConsumerRecords <?, ?> data , Consumer <?, ?> consumer ,
128
+ MessageListenerContainer container , Runnable invokeListener ) {
129
+
130
+ ErrorHandlingUtils .setRetryListeners (getRetryListeners ());
131
+ try {
132
+ this .fallbackBatchHandler .handleBatch (thrownException , data , consumer , container , invokeListener );
133
+ }
134
+ finally {
135
+ ErrorHandlingUtils .clearRetryListeners ();
136
+ }
137
+ }
138
+
127
139
private int findIndex (ConsumerRecords <?, ?> data , ConsumerRecord <?, ?> record ) {
128
140
if (record == null ) {
129
141
return -1 ;
0 commit comments