Commit 8cc2301
committed
GH-1633: Do not stop parent container when fenced
Resolves #1633
Only the child container instance should be stopped when a producer is
fenced.
Tested with a Boot Application:
```java
@SpringBootApplication
public class Kgh1633Application {
public static void main(String[] args) {
SpringApplication.run(Kgh1633Application.class, args);
}
@Autowired
KafkaTemplate<String, String> template;
@KafkaListener(id = "kgh1633a", topics = "kgh1633")
public void listen(String in) throws InterruptedException {
System.out.println(in);
this.template.send("kgh1633-1", "foo");
Thread.sleep(10_000);
}
@bean
public NewTopic topic1() {
return TopicBuilder.name("kgh1633").partitions(1).replicas(1).build();
}
@bean
public NewTopic topic2() {
return TopicBuilder.name("kgh1633-1").partitions(1).replicas(1).build();
}
// @eventlistener
// public void started(ConsumerStartedEvent event) {
// // temporary until GH-1633 is fixed
// KafkaMessageListenerContainer<?, ?> container = (KafkaMessageListenerContainer<?, ?>) event.getSource();
// container.setEmergencyStop(() -> container.stop(() -> { }));
// }
@eventlistener
public void stopped(ConsumerStoppedEvent event) {
((KafkaMessageListenerContainer<?, ?>) event.getSource()).start();
}
}
@component
class Customizer {
Customizer(AbstractKafkaListenerContainerFactory<?, ?, ?> factory) {
factory.getContainerProperties().setStopContainerWhenFenced(true);
}
}
```
```properties
spring.kafka.producer.transaction-id-prefix=tx-
spring.kafka.producer.acks=all
spring.kafka.producer.properties.transaction.timeout.ms=5000
```1 parent 9d61d73 commit 8cc2301
File tree
1 file changed
+5
-1
lines changed- spring-kafka/src/main/java/org/springframework/kafka/listener
1 file changed
+5
-1
lines changedLines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1072 | 1072 | | |
1073 | 1073 | | |
1074 | 1074 | | |
1075 | | - | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
1076 | 1080 | | |
1077 | 1081 | | |
1078 | 1082 | | |
| |||
0 commit comments