Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-8734: expose JmsLisConSpec.observationRegistry #8764

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,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();
}

}
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