From 8d1d507b5931e238b92cb6ab96d3b819a578cf0f Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Fri, 13 Oct 2023 14:20:07 -0400 Subject: [PATCH] GH-8734: expose JmsLisConSpec.observationRegistry Fixes https://github.com/spring-projects/spring-integration/issues/8734 Expose `JmsListenerContainerSpec.observationRegistry(ObservationRegistry observationRegistry)` option --- .../jms/dsl/JmsListenerContainerSpec.java | 12 ++++++++++++ .../integration/jms/dsl/JmsTests.java | 15 +++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) 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..73698475632 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,15 @@ public S clientId(String clientId) { return _this(); } + /** + * @param observationRegistry the observationRegistry. + * @return the spec. + * @see AbstractMessageListenerContainer#setObservationRegistry(ObservationRegistry) + * @since 6.2 + */ + 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();