Skip to content

Commit f958576

Browse files
committed
INT-4480: Use component type for ids in the flow
JIRA: https://jira.spring.io/browse/INT-4480 For better readability of bean names, e.g. from the metrics collectors, generate them from the component type instead of their fully qualified class names
1 parent 055e9a4 commit f958576

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

spring-integration-core/src/main/java/org/springframework/integration/dsl/context/IntegrationFlowBeanPostProcessor.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,14 @@ else if (fallbackId != null) {
429429
: fallbackId;
430430
}
431431

432-
String generatedBeanName = prefix + instance.getClass().getName();
432+
String generatedBeanName = prefix;
433+
if (instance instanceof NamedComponent) {
434+
generatedBeanName += ((NamedComponent) instance).getComponentType();
435+
}
436+
else {
437+
generatedBeanName += instance.getClass().getName();
438+
}
439+
433440
String id = generatedBeanName;
434441
int counter = -1;
435442
while (counter == -1 || this.beanFactory.containsBean(id)) {

spring-integration-core/src/test/java/org/springframework/integration/dsl/flows/IntegrationFlowTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,9 @@ public void testMethodInvokingMessageHandler() {
289289

290290
@Test
291291
public void testLambdas() {
292+
assertTrue(this.beanFactory.containsBean("lambdasFlow.filter#0"));
293+
assertTrue(this.beanFactory.containsBean("lambdasFlow.transformer#0"));
294+
292295
QueueChannel replyChannel = new QueueChannel();
293296
Message<?> message = MessageBuilder.withPayload("World")
294297
.setHeader(MessageHeaders.REPLY_CHANNEL, replyChannel)

src/reference/asciidoc/dsl.adoc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -650,8 +650,9 @@ Starting with version 5.1, this kind of `IntegrationFlow` is wrapped to the prox
650650

651651
Starting with version 5.0.6, the generated bean names for the components in an `IntegrationFlow` include the flow bean followed by a dot (`.`) as a prefix.
652652
For example, the `ConsumerEndpointFactoryBean` for the `.transform("Hello "::concat)` in the preceding sample results in a bean name of `lambdaFlow.o.s.i.config.ConsumerEndpointFactoryBean#0`.
653-
The `Transformer` implementation bean for that endpoint has a bean name of `lambdaFlow.o.s.i.transformer.MethodInvokingTransformer#0`.
654-
(In both cases, `o.s.i` is `org.springframework.integration`, shortened here to fit on the page.)
653+
(The `o.s.i` is a shortened from `org.springframework.integration` to fit on the page.)
654+
The `Transformer` implementation bean for that endpoint has a bean name of `lambdaFlow.transformer#0` (starting with version 5.1), where instead of a fully qualified name of the `MethodInvokingTransformer` class, its component type is used.
655+
The same pattern is applied for all the `NamedComponent` s when the bean name has to be generated within the flow.
655656
These generated bean names are prepended with the flow ID for purposes such as parsing logs or grouping components together in some analysis tool, as well as to avoid a race condition when we concurrently register integration flows at runtime.
656657
See <<java-dsl-runtime-flows>> for more information.
657658

@@ -662,12 +663,14 @@ We introduced the `FunctionExpression` class (an implementation of SpEL's `Expre
662663
The `Function<T, R>` option is provided for the DSL components, along with an `expression` option, when there is the implicit `Strategy` variant from Core Spring Integration.
663664
The following example shows how to use a function expression:
664665

666+
====
665667
[source,java]
666668
----
667669
.enrich(e -> e.requestChannel("enrichChannel")
668670
.requestPayload(Message::getPayload)
669671
.propertyFunction("date", m -> new Date()))
670672
----
673+
====
671674

672675
The `FunctionExpression` also supports runtime type conversion, as is done in `SpelExpression`.
673676

@@ -677,6 +680,7 @@ The `FunctionExpression` also supports runtime type conversion, as is done in `S
677680
Some of `if...else` and `publish-subscribe` components provide the ability to specify their logic or mapping by using sub-flows.
678681
The simplest sample is `.publishSubscribeChannel()`, as the following example shows:
679682

683+
====
680684
[source,java]
681685
----
682686
@Bean
@@ -693,8 +697,10 @@ public IntegrationFlow subscribersFlow() {
693697
.channel(c -> c.queue("subscriber3Results"));
694698
}
695699
----
700+
====
696701

697-
You can achieve the same result with separate `IntegrationFlow` `@Bean` definitions, but we hope you find the sub-flow style of logic composition useful. We find that it results in shorter (and so more readable) code.
702+
You can achieve the same result with separate `IntegrationFlow` `@Bean` definitions, but we hope you find the sub-flow style of logic composition useful.
703+
We find that it results in shorter (and so more readable) code.
698704

699705
A similar `publish-subscribe` sub-flow composition provides the `.routeToRecipients()` method.
700706

src/reference/asciidoc/whats-new.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ The `IntegrationFlowContext` is now an interface and `IntegrationFlowRegistratio
3939
A new `logAndReply()` operator has been introduced for convenience when you wish to log at the end of a flow for request-reply configurations.
4040
This avoid confusion with `log()` which is treated as a one-way end flow component.
4141

42+
A generated bean name for any `NamedComponent` within an integration flow is now based on the component type for better readability from visual tools, logs analyzers and metrics collectors.
43+
4244
[[x5.1-dispatcher-exceptions]]
4345
==== Dispatcher Exceptions
4446

0 commit comments

Comments
 (0)