diff --git a/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/JmsListenerContainerSpec.java b/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/JmsListenerContainerSpec.java index d4bf5857bdb..e3c54682bea 100644 --- a/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/JmsListenerContainerSpec.java +++ b/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/JmsListenerContainerSpec.java @@ -16,6 +16,7 @@ package org.springframework.integration.jms.dsl; +import io.micrometer.observation.ObservationRegistry; import jakarta.jms.Destination; import jakarta.jms.ExceptionListener; @@ -158,4 +159,16 @@ public S clientId(String clientId) { return _this(); } + /** + * Configure an {@link ObservationRegistry} to use in the target listener container. + * @param observationRegistry the observationRegistry. + * @return the spec. + * @since 6.2 + * @see AbstractMessageListenerContainer#setObservationRegistry(ObservationRegistry) + */ + public S observationRegistry(ObservationRegistry observationRegistry) { + this.target.setObservationRegistry(observationRegistry); + return _this(); + } + } diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/dsl/JmsTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/dsl/JmsTests.java index 4924cdb2a98..19066acea23 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/dsl/JmsTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/dsl/JmsTests.java @@ -22,6 +22,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; +import io.micrometer.observation.ObservationRegistry; import io.micrometer.observation.tck.TestObservationRegistry; import io.micrometer.observation.tck.TestObservationRegistryAssert; import jakarta.jms.JMSException; @@ -56,6 +57,7 @@ import org.springframework.integration.handler.AbstractReplyProducingMessageHandler; import org.springframework.integration.jms.ActiveMQMultiContextTests; import org.springframework.integration.jms.JmsDestinationPollingSource; +import org.springframework.integration.jms.JmsMessageDrivenEndpoint; import org.springframework.integration.jms.SubscribableJmsChannel; import org.springframework.integration.scheduling.PollerMetadata; import org.springframework.integration.support.MessageBuilder; @@ -129,6 +131,9 @@ public class JmsTests extends ActiveMQMultiContextTests { @Qualifier("jmsOutboundGateway.handler") private MessageHandler jmsOutboundGatewayHandler; + @Autowired + JmsMessageDrivenEndpoint containerWithObservation; + @Autowired private AtomicBoolean jmsMessageDrivenChannelCalled; @@ -192,6 +197,9 @@ public void testJmsOutboundInboundFlow() { .extracting(Message::getPayload) .isEqualTo("HELLO THROUGH THE JMS"); + assertThat(TestUtils.getPropertyValue(this.containerWithObservation, "listenerContainer.observationRegistry")) + .isSameAs(this.observationRegistry); + this.jmsOutboundInboundChannel.send(MessageBuilder.withPayload("hello THROUGH the JMS") .setHeader(SimpMessageHeaderAccessor.DESTINATION_HEADER, "jmsMessageDriven") .build()); @@ -406,13 +414,16 @@ public IntegrationFlow pubSubFlow(SubscribableJmsChannel jmsPublishSubscribeChan } @Bean - public IntegrationFlow jmsMessageDrivenFlow() { + public IntegrationFlow jmsMessageDrivenFlow(ObservationRegistry observationRegistry) { return IntegrationFlow .from(Jms.messageDrivenChannelAdapter(amqFactory, DefaultMessageListenerContainer.class) .outputChannel(jmsMessageDrivenInputChannel()) .destination("jmsMessageDriven") - .configureListenerContainer(c -> c.clientId("foo"))) + .configureListenerContainer(c -> c + .clientId("foo") + .observationRegistry(observationRegistry)) + .id("containerWithObservation")) .transform(String::toLowerCase) .channel(jmsOutboundInboundReplyChannel()) .get();