GH-3386: Add method signature for gateway proxy (#3387)
* GH-3386: Add method signature for gateway proxy Fixes https://github.com/spring-projects/spring-integration/issues/3386 All the gateway proxy method invokers are supplied with the same bean name inherited from the proxy. * Add method signature for proxy method bean to fine-grain the management for those bean in the logs, message history and metrics * * Use `Class.getSimpleName()` instead to make gateway names less verbose
This commit is contained in:
@@ -153,12 +153,19 @@ public class GatewayDslTests {
|
||||
@Autowired
|
||||
private RoutingGateway routingGateway;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("&routingGateway")
|
||||
private GatewayProxyFactoryBean routingGatewayProxy;
|
||||
|
||||
@Test
|
||||
void testRoutingGateway() {
|
||||
String result = this.routingGateway.route1("test1");
|
||||
assertThat(result).isEqualTo("route1");
|
||||
result = this.routingGateway.route2("test2");
|
||||
assertThat(result).isEqualTo("route2");
|
||||
MessagingGatewaySupport gatewayMethod = this.routingGatewayProxy.getGateways().values().iterator().next();
|
||||
assertThat(gatewayMethod.getComponentName())
|
||||
.isEqualTo("routingGateway#route1(Object)");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -211,9 +218,9 @@ public class GatewayDslTests {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public IntegrationFlow routingGateway() {
|
||||
public IntegrationFlow routingGatewayFlow() {
|
||||
return IntegrationFlows.from(RoutingGateway.class,
|
||||
(gateway) -> gateway.header("gatewayMethod", MethodArgsHolder::getMethod))
|
||||
(gateway) -> gateway.beanName("routingGateway").header("gatewayMethod", MethodArgsHolder::getMethod))
|
||||
.route(Message.class, (message) ->
|
||||
message.getHeaders().get("gatewayMethod", Method.class).getName(),
|
||||
(router) -> router
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,13 +18,11 @@ package org.springframework.integration.handler;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -44,7 +42,7 @@ import org.springframework.messaging.MessageHandlingException;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.messaging.PollableChannel;
|
||||
import org.springframework.messaging.support.ErrorMessage;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
import org.springframework.util.concurrent.SettableListenableFuture;
|
||||
|
||||
@@ -57,7 +55,7 @@ import org.springframework.util.concurrent.SettableListenableFuture;
|
||||
*
|
||||
* @since 2.0.1
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringJUnitConfig
|
||||
public class ServiceActivatorDefaultFrameworkMethodTests {
|
||||
|
||||
@Autowired
|
||||
@@ -106,7 +104,8 @@ public class ServiceActivatorDefaultFrameworkMethodTests {
|
||||
this.gatewayTestInputChannel.send(message);
|
||||
Message<?> reply = replyChannel.receive(0);
|
||||
assertThat(reply.getHeaders().get("history").toString())
|
||||
.isEqualTo("gatewayTestInputChannel,gatewayTestService,gateway,requestChannel,replyChannel");
|
||||
.isEqualTo("gatewayTestInputChannel,gatewayTestService," +
|
||||
"gateway#exchange(Message),requestChannel,replyChannel");
|
||||
|
||||
Message<?> message2 = MessageBuilder.withPayload("foo").setReplyChannel(replyChannel).build();
|
||||
|
||||
@@ -197,19 +196,11 @@ public class ServiceActivatorDefaultFrameworkMethodTests {
|
||||
|
||||
@Test
|
||||
public void testFailOnDoubleReference() {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext(this.getClass().getSimpleName() + "-fail-context.xml",
|
||||
this.getClass()).close();
|
||||
fail("Expected exception due to 2 endpoints referencing the same bean");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertThat(e).isInstanceOf(BeanCreationException.class);
|
||||
assertThat(e.getCause()).isInstanceOf(BeanCreationException.class);
|
||||
assertThat(e.getCause().getCause()).isInstanceOf(IllegalArgumentException.class);
|
||||
assertThat(e.getCause().getCause().getMessage())
|
||||
.contains("An AbstractMessageProducingMessageHandler may only be referenced once");
|
||||
}
|
||||
|
||||
assertThatExceptionOfType(BeanCreationException.class)
|
||||
.isThrownBy(() ->
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-fail-context.xml", getClass()))
|
||||
.withMessageContaining("An AbstractMessageProducingMessageHandler may only be referenced once")
|
||||
.withRootCauseExactlyInstanceOf(IllegalArgumentException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -228,7 +219,7 @@ public class ServiceActivatorDefaultFrameworkMethodTests {
|
||||
@Test
|
||||
public void testAsyncWithDirectReply() {
|
||||
DirectChannel replyChannel = new DirectChannel();
|
||||
final AtomicReference<Message<?>> reply = new AtomicReference<Message<?>>();
|
||||
final AtomicReference<Message<?>> reply = new AtomicReference<>();
|
||||
replyChannel.subscribe(reply::set);
|
||||
|
||||
Message<?> message = MessageBuilder.withPayload("testing").setReplyChannel(replyChannel).build();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.integration.history;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
@@ -24,8 +25,8 @@ import java.util.Properties;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
@@ -77,7 +78,7 @@ public class MessageHistoryIntegrationTests {
|
||||
.get(MessageHistory.HEADER_NAME, MessageHistory.class).iterator();
|
||||
|
||||
Properties event = historyIterator.next();
|
||||
assertThat(event.getProperty(MessageHistory.NAME_PROPERTY)).isEqualTo("sampleGateway");
|
||||
assertThat(event.getProperty(MessageHistory.NAME_PROPERTY)).isEqualTo("sampleGateway#echo(String)");
|
||||
assertThat(event.getProperty(MessageHistory.TYPE_PROPERTY)).isEqualTo("gateway");
|
||||
|
||||
event = historyIterator.next();
|
||||
@@ -208,7 +209,7 @@ public class MessageHistoryIntegrationTests {
|
||||
.get(MessageHistory.HEADER_NAME, MessageHistory.class).iterator();
|
||||
assertThat(historyIterator.hasNext()).isTrue();
|
||||
Properties gatewayHistory = historyIterator.next();
|
||||
assertThat(gatewayHistory.get("name")).isEqualTo("sampleGateway");
|
||||
assertThat(gatewayHistory.get("name")).isEqualTo("sampleGateway#echo(String)");
|
||||
assertThat(historyIterator.hasNext()).isTrue();
|
||||
Properties chainHistory = historyIterator.next();
|
||||
assertThat(chainHistory.get("name")).isEqualTo("sampleChain");
|
||||
@@ -223,14 +224,16 @@ public class MessageHistoryIntegrationTests {
|
||||
ac.close();
|
||||
}
|
||||
|
||||
@Test(expected = BeanCreationException.class)
|
||||
@Test
|
||||
public void testMessageHistoryMoreThanOneNamespaceFail() {
|
||||
new ClassPathXmlApplicationContext("messageHistoryWithHistoryWriterNamespace-fail.xml",
|
||||
MessageHistoryIntegrationTests.class).close();
|
||||
assertThatExceptionOfType(BeanCreationException.class)
|
||||
.isThrownBy(() ->
|
||||
new ClassPathXmlApplicationContext("messageHistoryWithHistoryWriterNamespace-fail.xml",
|
||||
MessageHistoryIntegrationTests.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void testMessageHistoryWithHistoryPerformance() {
|
||||
ConfigurableApplicationContext acWithHistory = new ClassPathXmlApplicationContext("perfWithMessageHistory.xml",
|
||||
MessageHistoryIntegrationTests.class);
|
||||
|
||||
@@ -221,15 +221,23 @@ public class MicrometerMetricsTests {
|
||||
this.gates.oneWay("foo");
|
||||
this.gates.twoWay("bar");
|
||||
assertThat(registry.get("spring.integration.send")
|
||||
.tag("name", "gates")
|
||||
.tag("name", "gates#oneWay(String)")
|
||||
.tag("result", "success")
|
||||
.timer().count()).isEqualTo(2);
|
||||
.timer().count()).isEqualTo(1);
|
||||
assertThat(registry.get("spring.integration.send")
|
||||
.tag("name", "gates#twoWay(String)")
|
||||
.tag("result", "success")
|
||||
.timer().count()).isEqualTo(1);
|
||||
this.gatesFlow.oneWay("foo");
|
||||
this.gatesFlow.twoWay("bar");
|
||||
assertThat(registry.get("spring.integration.send")
|
||||
.tag("name", "gatesFlow.gateway")
|
||||
.tag("name", "gatesFlow.gateway#oneWay(String)")
|
||||
.tag("result", "success")
|
||||
.timer().count()).isEqualTo(2);
|
||||
.timer().count()).isEqualTo(1);
|
||||
assertThat(registry.get("spring.integration.send")
|
||||
.tag("name", "gatesFlow.gateway#twoWay(String)")
|
||||
.tag("result", "success")
|
||||
.timer().count()).isEqualTo(1);
|
||||
assertThat(registry.get("spring.integration.send")
|
||||
.tag("name", "customGw")
|
||||
.tag("result", "success")
|
||||
|
||||
Reference in New Issue
Block a user