Skip to content

Commit

Permalink
GH-9478: Fix MessagingGatewaySupport.onInit() for calling `super.on…
Browse files Browse the repository at this point in the history
…Init()`

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

(cherry picked from commit a8174d5)
  • Loading branch information
artembilan authored and spring-builds committed Sep 17, 2024
1 parent 6cadbfb commit ad692ea
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ protected void onInit() {
if (!this.replyTimeoutSet) {
this.messagingTemplate.setReceiveTimeout(endpointsDefaultTimeout);
}
super.onInit();
this.initialized = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,13 @@
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="group-id">
<xsd:annotation>
<xsd:documentation>
Set the 'group.id' KafkaConsumer property.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attributeGroup ref="kafkaTemplate"/>
</xsd:complexType>

Expand Down Expand Up @@ -764,13 +771,6 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="group-id">
<xsd:annotation>
<xsd:documentation>
Set the 'group.id' KafkaConsumer property.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:attributeGroup>

<xsd:attributeGroup name="headerMapper">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
retry-template="retryTemplate"
recovery-callback="recoveryCallback"
bind-source-record="true"
on-partitions-assigned-seek-callback="onPartitionsAssignedSeekCallback"/>
on-partitions-assigned-seek-callback="onPartitionsAssignedSeekCallback"
role="testRole"/>

<bean id="template" class="org.mockito.Mockito" factory-method="mock">
<constructor-arg value="org.springframework.kafka.core.KafkaTemplate" type="java.lang.Class"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 the original author or authors.
* Copyright 2019-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,6 +21,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.integration.kafka.inbound.KafkaInboundGateway;
import org.springframework.integration.support.SmartLifecycleRoleController;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.kafka.listener.KafkaMessageListenerContainer;
import org.springframework.test.annotation.DirtiesContext;
Expand All @@ -45,6 +46,9 @@ public class KafkaInboundGatewayTests {
@Autowired
private ApplicationContext context;

@Autowired
SmartLifecycleRoleController roleController;

@Test
public void testProps() {
assertThat(this.gateway1.isAutoStartup()).isFalse();
Expand All @@ -69,6 +73,8 @@ public void testProps() {
assertThat(TestUtils.getPropertyValue(this.gateway1, "messagingTemplate.sendTimeout")).isEqualTo(5000L);
assertThat(TestUtils.getPropertyValue(this.gateway1, "messagingTemplate.receiveTimeout")).isEqualTo(43L);
assertThat(TestUtils.getPropertyValue(this.gateway1, "bindSourceRecord", Boolean.class)).isTrue();
assertThat(this.roleController.getRoles()).contains("testRole");
assertThat(this.roleController.getEndpointsRunningStatus("testRole")).containsEntry("gateway1", false);
}

}

0 comments on commit ad692ea

Please sign in to comment.