GH-8734: expose JmsLisConSpec.observationRegistry (#8764)
* GH-8734: expose JmsLisConSpec.observationRegistry Fixes https://github.com/spring-projects/spring-integration/issues/8734 Expose `JmsListenerContainerSpec.observationRegistry(ObservationRegistry observationRegistry)` option * * Fix Checkstyle violation for Javadoc
This commit is contained in:
@@ -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 class JmsListenerContainerSpec<S extends JmsListenerContainerSpec<S, C>,
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.concurrent.TimeUnit;
|
||||
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.endpoint.MethodInvokingMessageSource;
|
||||
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 class JmsTests extends ActiveMQMultiContextTests {
|
||||
.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 class JmsTests extends ActiveMQMultiContextTests {
|
||||
}
|
||||
|
||||
@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"))
|
||||
.<String, String>transform(String::toLowerCase)
|
||||
.channel(jmsOutboundInboundReplyChannel())
|
||||
.get();
|
||||
|
||||
Reference in New Issue
Block a user