Skip to content

Commit a8174d5

Browse files
committed
GH-9478: Fix MessagingGatewaySupport.onInit() for calling super.onInit()
Fixes: #9478 Issue link: #9478 Any `MessagingGatewaySupport` implementation does not register itself into a `SmartLifecycleRoleController` because they don't call `super.onInit()` of the `AbstractEndpoint` * Fix `MessagingGatewaySupport` for calling `super.onInit()` from its `onInit()` * Verify `SmartLifecycleRoleController` registration in the `KafkaInboundGatewayTests` * Remove out of use XML `group-id` attribute from Kafka channel adapter and move it to the `channel` XSD as the place where it is really used **Auto-cherry-pick to `6.3.x` & `6.2.x`**
1 parent 4932990 commit a8174d5

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

spring-integration-core/src/main/java/org/springframework/integration/gateway/MessagingGatewaySupport.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ protected void onInit() {
423423
if (!this.replyTimeoutSet) {
424424
this.messagingTemplate.setReceiveTimeout(endpointsDefaultTimeout);
425425
}
426+
super.onInit();
426427
this.initialized = true;
427428
}
428429

spring-integration-kafka/src/main/resources/org/springframework/integration/kafka/config/spring-integration-kafka.xsd

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,13 @@
453453
</xsd:documentation>
454454
</xsd:annotation>
455455
</xsd:attribute>
456+
<xsd:attribute name="group-id">
457+
<xsd:annotation>
458+
<xsd:documentation>
459+
Set the 'group.id' KafkaConsumer property.
460+
</xsd:documentation>
461+
</xsd:annotation>
462+
</xsd:attribute>
456463
<xsd:attributeGroup ref="kafkaTemplate"/>
457464
</xsd:complexType>
458465

@@ -764,13 +771,6 @@
764771
</xsd:appinfo>
765772
</xsd:annotation>
766773
</xsd:attribute>
767-
<xsd:attribute name="group-id">
768-
<xsd:annotation>
769-
<xsd:documentation>
770-
Set the 'group.id' KafkaConsumer property.
771-
</xsd:documentation>
772-
</xsd:annotation>
773-
</xsd:attribute>
774774
</xsd:attributeGroup>
775775

776776
<xsd:attributeGroup name="headerMapper">

spring-integration-kafka/src/test/java/org/springframework/integration/kafka/config/xml/KafkaInboundGatewayTests-context.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
retry-template="retryTemplate"
2222
recovery-callback="recoveryCallback"
2323
bind-source-record="true"
24-
on-partitions-assigned-seek-callback="onPartitionsAssignedSeekCallback"/>
24+
on-partitions-assigned-seek-callback="onPartitionsAssignedSeekCallback"
25+
role="testRole"/>
2526

2627
<bean id="template" class="org.mockito.Mockito" factory-method="mock">
2728
<constructor-arg value="org.springframework.kafka.core.KafkaTemplate" type="java.lang.Class"/>

spring-integration-kafka/src/test/java/org/springframework/integration/kafka/config/xml/KafkaInboundGatewayTests.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 the original author or authors.
2+
* Copyright 2019-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
2121
import org.springframework.beans.factory.annotation.Autowired;
2222
import org.springframework.context.ApplicationContext;
2323
import org.springframework.integration.kafka.inbound.KafkaInboundGateway;
24+
import org.springframework.integration.support.SmartLifecycleRoleController;
2425
import org.springframework.integration.test.util.TestUtils;
2526
import org.springframework.kafka.listener.KafkaMessageListenerContainer;
2627
import org.springframework.test.annotation.DirtiesContext;
@@ -45,6 +46,9 @@ public class KafkaInboundGatewayTests {
4546
@Autowired
4647
private ApplicationContext context;
4748

49+
@Autowired
50+
SmartLifecycleRoleController roleController;
51+
4852
@Test
4953
public void testProps() {
5054
assertThat(this.gateway1.isAutoStartup()).isFalse();
@@ -69,6 +73,8 @@ public void testProps() {
6973
assertThat(TestUtils.getPropertyValue(this.gateway1, "messagingTemplate.sendTimeout")).isEqualTo(5000L);
7074
assertThat(TestUtils.getPropertyValue(this.gateway1, "messagingTemplate.receiveTimeout")).isEqualTo(43L);
7175
assertThat(TestUtils.getPropertyValue(this.gateway1, "bindSourceRecord", Boolean.class)).isTrue();
76+
assertThat(this.roleController.getRoles()).contains("testRole");
77+
assertThat(this.roleController.getEndpointsRunningStatus("testRole")).containsEntry("gateway1", false);
7278
}
7379

7480
}

0 commit comments

Comments
 (0)