Fix IntegrationFlowContext concurrency issue
When we register `IntegrationFlow` s concurrently at runtime, we may end up with the problem when we register the same object with the same bean name, but in different places. Or when we turn off bean overriding, we end up with the exception that bean with the name already registered * Wrap `IntegrationFlow` bean registration in the `StandardIntegrationFlowContext` into the `Lock` when its bean name is generating * Make `StandardIntegrationFlowContext.registry` as `ConcurrentHashMap` to avoid `ConcurrentModificationException` during `put()` and `remove()` * Fix concurrency for beans registration with the generation names in the `IntegrationFlowBeanPostProcessor` using an `IntegrationFlow` id as a prefix for uniqueness. **Cherry-pick to 5.0.x** Fix generated bean name in the WebFluxDslTests Use only single `Lock` in the `StandardIntegrationFlowContext`: we don't need a fully blown `LockRegistry` there anymore since we have only one synchronization block there and it is always around the same type * Add `What's New` note, and mention changes in the `dsl.adoc` Minor doc polishing. # Conflicts: # spring-integration-core/src/main/java/org/springframework/integration/dsl/context/StandardIntegrationFlowContext.java # spring-integration-core/src/test/java/org/springframework/integration/dsl/manualflow/ManualFlowTests.java # src/reference/asciidoc/dsl.adoc # src/reference/asciidoc/whats-new.adoc
This commit is contained in:
@@ -578,6 +578,12 @@ The result of this definition is the same bunch of Integration components wired
|
||||
Only limitation is here, that this flow is started with named direct channel - `lambdaFlow.input`.
|
||||
And Lambda flow can't start from `MessageSource` or `MessageProducer`.
|
||||
|
||||
Starting with _version 5.0.5_, the generated bean names for the components in an `IntegrationFlow` include the flow bean followed by a dot as a prefix.
|
||||
For example the `ConsumerEndpointFactoryBean` for the `.transform("Hello "::concat)` in the sample above, will end up with te bean name like `lambdaFlow.org.springframework.integration.config.ConsumerEndpointFactoryBean#0`.
|
||||
The `Transformer` implementation bean for that endpoint will have a bean name such as `lambdaFlow.org.springframework.integration.transformer.MethodInvokingTransformer#0`.
|
||||
These generated bean names are prepended with the flow id prefix 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.
|
||||
See <<java-dsl-runtime-flows>> for more information.
|
||||
|
||||
[[java-dsl-function-expression]]
|
||||
=== FunctionExpression
|
||||
|
||||
@@ -889,6 +895,10 @@ Usually those additional beans are connection factories (AMQP, JMS, (S)FTP, TCP/
|
||||
Such a dynamically registered `IntegrationFlow` and all its dependant beans can be removed afterwards using `IntegrationFlowRegistration.destroy()` callback.
|
||||
See `IntegrationFlowContext` JavaDocs for more information.
|
||||
|
||||
NOTE: Starting with _version 5.0.5_, all generated bean names in an `IntegrationFlow` definition are prepended with flow id as a prefix.
|
||||
It is recommended to always specify an explicit flow id, otherwise a synchronization barrier is initiated in the `IntegrationFlowContext` to generate the bean name for the `IntegrationFlow` and register its beans.
|
||||
We synchronize on these two operations to avoid a race condition when the same generated bean name may be used for different `IntegrationFlow` instances.
|
||||
|
||||
[[java-dsl-gateway]]
|
||||
=== IntegrationFlow as Gateway
|
||||
|
||||
|
||||
@@ -315,3 +315,10 @@ Further changes were made in 5.0.4; if using Micrometer, a minimum of version 5.
|
||||
|
||||
Introduced in _version 5.0.4_, this annotation provides control over bean naming when using Java configuration.
|
||||
See <<endpoint-bean-names>> for more information.
|
||||
|
||||
==== Integration Flows: Generated bean names
|
||||
|
||||
Starting with _version 5.0.5_, generated bean names for the components in an `IntegrationFlow` include the flow bean name, followed by a dot, as a prefix.
|
||||
|
||||
See <<java-dsl-flows>> for more information.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user