Skip to content

Commit c550186

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 4a85849 commit c550186

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
@@ -649,8 +649,9 @@ Starting with version 5.1, this kind of `IntegrationFlow` is wrapped to the prox
649649

650650
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.
651651
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`.
652-
The `Transformer` implementation bean for that endpoint has a bean name of `lambdaFlow.o.s.i.transformer.MethodInvokingTransformer#0`.
653-
(In both cases, `o.s.i` is `org.springframework.integration`, shortened here to fit on the page.)
652+
(The `o.s.i` is a shortened from `org.springframework.integration` to fit on the page.)
653+
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.
654+
The same pattern is applied for all the `NamedComponent` s when the bean name has to be generated within the flow.
654655
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.
655656
See <<java-dsl-runtime-flows>> for more information.
656657

@@ -661,12 +662,14 @@ We introduced the `FunctionExpression` class (an implementation of SpEL's `Expre
661662
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.
662663
The following example shows how to use a function expression:
663664

665+
====
664666
[source,java]
665667
----
666668
.enrich(e -> e.requestChannel("enrichChannel")
667669
.requestPayload(Message::getPayload)
668670
.propertyFunction("date", m -> new Date()))
669671
----
672+
====
670673

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

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

682+
====
679683
[source,java]
680684
----
681685
@Bean
@@ -692,8 +696,10 @@ public IntegrationFlow subscribersFlow() {
692696
.channel(c -> c.queue("subscriber3Results"));
693697
}
694698
----
699+
====
695700

696-
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.
701+
You can achieve the same result with separate `IntegrationFlow` `@Bean` definitions, but we hope you find the sub-flow style of logic composition useful.
702+
We find that it results in shorter (and so more readable) code.
697703

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

src/reference/asciidoc/whats-new.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ The following changes have been made in version 5.1:
3636

3737
The `IntegrationFlowContext` is now an interface and `IntegrationFlowRegistration` is an inner interface of `IntegrationFlowContext`.
3838

39+
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.
40+
3941
[[x5.1-dispatcher-exceptions]]
4042
==== Dispatcher Exceptions
4143

0 commit comments

Comments
 (0)