|
55 | 55 | * @author Nurettin Yilmaz
|
56 | 56 | * @author Denis Washington
|
57 | 57 | * @author Gary Russell
|
| 58 | + * @author Julien Wittouck |
58 | 59 | *
|
59 | 60 | * @since 1.1.4
|
60 | 61 | */
|
@@ -100,6 +101,8 @@ public class StreamsBuilderFactoryBean extends AbstractFactoryBean<StreamsBuilde
|
100 | 101 |
|
101 | 102 | private Duration closeTimeout = DEFAULT_CLOSE_TIMEOUT;
|
102 | 103 |
|
| 104 | + private boolean leaveGroupOnClose = false; |
| 105 | + |
103 | 106 | private KafkaStreams kafkaStreams;
|
104 | 107 |
|
105 | 108 | private volatile boolean running;
|
@@ -225,6 +228,15 @@ public void setCloseTimeout(int closeTimeout) {
|
225 | 228 | this.closeTimeout = Duration.ofSeconds(closeTimeout); // NOSONAR (sync)
|
226 | 229 | }
|
227 | 230 |
|
| 231 | + /** |
| 232 | + * Specify if the consumer should leave the group when stopping Kafka Streams. Defaults to false. |
| 233 | + * @param leaveGroupOnClose true to leave the group when stopping the Streams |
| 234 | + * @since 3.2.0 |
| 235 | + */ |
| 236 | + public void setLeaveGroupOnClose(boolean leaveGroupOnClose) { |
| 237 | + this.leaveGroupOnClose = leaveGroupOnClose; |
| 238 | + } |
| 239 | + |
228 | 240 | /**
|
229 | 241 | * Providing access to the associated {@link Topology} of this
|
230 | 242 | * {@link StreamsBuilderFactoryBean}.
|
@@ -383,7 +395,10 @@ public void stop() {
|
383 | 395 | if (this.running) {
|
384 | 396 | try {
|
385 | 397 | if (this.kafkaStreams != null) {
|
386 |
| - this.kafkaStreams.close(this.closeTimeout); |
| 398 | + this.kafkaStreams.close(new KafkaStreams.CloseOptions() |
| 399 | + .timeout(this.closeTimeout) |
| 400 | + .leaveGroup(this.leaveGroupOnClose) |
| 401 | + ); |
387 | 402 | if (this.cleanupConfig.cleanupOnStop()) {
|
388 | 403 | this.kafkaStreams.cleanUp();
|
389 | 404 | }
|
|
0 commit comments