14
14
* limitations under the License.
15
15
*/
16
16
17
- package org .springframework .kafka .listener . config ;
17
+ package org .springframework .kafka .listener ;
18
18
19
19
import java .util .Arrays ;
20
20
import java .util .LinkedHashSet ;
24
24
import org .apache .kafka .clients .consumer .OffsetCommitCallback ;
25
25
26
26
import org .springframework .core .task .AsyncListenableTaskExecutor ;
27
- import org .springframework .kafka .listener .AbstractMessageListenerContainer ;
28
- import org .springframework .kafka .listener .AbstractMessageListenerContainer .AckMode ;
29
- import org .springframework .kafka .listener .BatchErrorHandler ;
30
- import org .springframework .kafka .listener .ErrorHandler ;
31
- import org .springframework .kafka .listener .GenericErrorHandler ;
32
27
import org .springframework .kafka .support .LogIfLevelEnabled ;
33
28
import org .springframework .kafka .support .TopicPartitionInitialOffset ;
34
29
import org .springframework .scheduling .TaskScheduler ;
46
41
*/
47
42
public class ContainerProperties {
48
43
44
+ /**
45
+ * The offset commit behavior enumeration.
46
+ */
47
+ public enum AckMode {
48
+
49
+ /**
50
+ * Commit after each record is processed by the listener.
51
+ */
52
+ RECORD ,
53
+
54
+ /**
55
+ * Commit whatever has already been processed before the next poll.
56
+ */
57
+ BATCH ,
58
+
59
+ /**
60
+ * Commit pending updates after
61
+ * {@link ContainerProperties#setAckTime(long) ackTime} has elapsed.
62
+ */
63
+ TIME ,
64
+
65
+ /**
66
+ * Commit pending updates after
67
+ * {@link ContainerProperties#setAckCount(int) ackCount} has been
68
+ * exceeded.
69
+ */
70
+ COUNT ,
71
+
72
+ /**
73
+ * Commit pending updates after
74
+ * {@link ContainerProperties#setAckCount(int) ackCount} has been
75
+ * exceeded or after {@link ContainerProperties#setAckTime(long)
76
+ * ackTime} has elapsed.
77
+ */
78
+ COUNT_TIME ,
79
+
80
+ /**
81
+ * User takes responsibility for acks using an
82
+ * {@link AcknowledgingMessageListener}.
83
+ */
84
+ MANUAL ,
85
+
86
+ /**
87
+ * User takes responsibility for acks using an
88
+ * {@link AcknowledgingMessageListener}. The consumer
89
+ * immediately processes the commit.
90
+ */
91
+ MANUAL_IMMEDIATE ,
92
+
93
+ }
94
+
49
95
private static final long DEFAULT_POLL_TIMEOUT = 1000L ;
50
96
51
97
private static final int DEFAULT_SHUTDOWN_TIMEOUT = 10000 ;
@@ -82,7 +128,7 @@ public class ContainerProperties {
82
128
* {@link org.springframework.kafka.listener.AcknowledgingMessageListener}.
83
129
* </ul>
84
130
*/
85
- private AbstractMessageListenerContainer . AckMode ackMode = AckMode .BATCH ;
131
+ private AckMode ackMode = AckMode .BATCH ;
86
132
87
133
/**
88
134
* The number of outstanding record count after which offsets should be
@@ -114,11 +160,6 @@ public class ContainerProperties {
114
160
*/
115
161
private AsyncListenableTaskExecutor consumerTaskExecutor ;
116
162
117
- /**
118
- * The error handler to call when the listener throws an exception.
119
- */
120
- private GenericErrorHandler <?> errorHandler ;
121
-
122
163
/**
123
164
* The timeout for shutting down the container. This is the maximum amount of
124
165
* time that the invocation to {@code #stop(Runnable)} will block for, before
@@ -209,7 +250,7 @@ public void setMessageListener(Object messageListener) {
209
250
* </ul>
210
251
* @param ackMode the {@link AckMode}; default BATCH.
211
252
*/
212
- public void setAckMode (AbstractMessageListenerContainer . AckMode ackMode ) {
253
+ public void setAckMode (AckMode ackMode ) {
213
254
Assert .notNull (ackMode , "'ackMode' cannot be null" );
214
255
this .ackMode = ackMode ;
215
256
}
@@ -243,22 +284,6 @@ public void setAckTime(long ackTime) {
243
284
this .ackTime = ackTime ;
244
285
}
245
286
246
- /**
247
- * Set the error handler to call when the listener throws an exception.
248
- * @param errorHandler the error handler.
249
- */
250
- public void setErrorHandler (ErrorHandler errorHandler ) {
251
- this .errorHandler = errorHandler ;
252
- }
253
-
254
- /**
255
- * Set the batch error handler to call when the listener throws an exception.
256
- * @param errorHandler the error handler.
257
- */
258
- public void setBatchErrorHandler (BatchErrorHandler errorHandler ) {
259
- this .errorHandler = errorHandler ;
260
- }
261
-
262
287
/**
263
288
* Set the executor for threads that poll the consumer.
264
289
* @param consumerTaskExecutor the executor
@@ -355,7 +380,7 @@ public TopicPartitionInitialOffset[] getTopicPartitions() {
355
380
return this .topicPartitions ;
356
381
}
357
382
358
- public AbstractMessageListenerContainer . AckMode getAckMode () {
383
+ public AckMode getAckMode () {
359
384
return this .ackMode ;
360
385
}
361
386
@@ -379,10 +404,6 @@ public AsyncListenableTaskExecutor getConsumerTaskExecutor() {
379
404
return this .consumerTaskExecutor ;
380
405
}
381
406
382
- public GenericErrorHandler <?> getGenericErrorHandler () {
383
- return this .errorHandler ;
384
- }
385
-
386
407
public long getShutdownTimeout () {
387
408
return this .shutdownTimeout ;
388
409
}
@@ -542,7 +563,6 @@ public String toString() {
542
563
+ ", pollTimeout=" + this .pollTimeout
543
564
+ (this .consumerTaskExecutor != null
544
565
? ", consumerTaskExecutor=" + this .consumerTaskExecutor : "" )
545
- + (this .errorHandler != null ? ", errorHandler=" + this .errorHandler : "" )
546
566
+ ", shutdownTimeout=" + this .shutdownTimeout
547
567
+ (this .consumerRebalanceListener != null
548
568
? ", consumerRebalanceListener=" + this .consumerRebalanceListener : "" )
0 commit comments