Skip to content

Commit

Permalink
spring-projectsGH-8734: expose JmsLisConSpec.observationRegistry
Browse files Browse the repository at this point in the history
Fixes spring-projects#8734

Expose `JmsListenerContainerSpec.observationRegistry(ObservationRegistry observationRegistry)` option
  • Loading branch information
artembilan committed Oct 13, 2023
1 parent f819f4b commit 8d1d507
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.springframework.integration.jms.dsl;

import io.micrometer.observation.ObservationRegistry;
import jakarta.jms.Destination;
import jakarta.jms.ExceptionListener;

Expand Down Expand Up @@ -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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -129,6 +131,9 @@ public class JmsTests extends ActiveMQMultiContextTests {
@Qualifier("jmsOutboundGateway.handler")
private MessageHandler jmsOutboundGatewayHandler;

@Autowired
JmsMessageDrivenEndpoint containerWithObservation;

@Autowired
private AtomicBoolean jmsMessageDrivenChannelCalled;

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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"))
.<String, String>transform(String::toLowerCase)
.channel(jmsOutboundInboundReplyChannel())
.get();
Expand Down

0 comments on commit 8d1d507

Please sign in to comment.