Skip to content

GH-3844: Rework messaging annotation with @Bean #3877

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

Merged
merged 2 commits into from
Aug 22, 2022
Merged

GH-3844: Rework messaging annotation with @Bean #3877

merged 2 commits into from
Aug 22, 2022

Conversation

artembilan
Copy link
Member

Fixes #3844

  • Make MessagingAnnotationPostProcessor as a BeanDefinitionRegistryPostProcessor
    to process bean definitions as early as possible and register respective messaging
    components at that early phase
  • Make bean definitions parsing logic optional for AOT and native mode since beans
    have bean parsed during AOT building phase
  • Introduce a BeanDefinitionPropertiesMapper for easier mapping
    of the annotation attributes to the target BeanDefinition
  • Remove @Bean-related logic from method parsing process
  • Change the logic for @Bean-based endpoint bean names:
    since we don't deal with methods on the bean definition phase, then method name
    does not make sense.
    It even may mislead if we @Bean name is based on a method by default, so we end up
    with duplicated word in the target endpoint bean name.
    Now we don't
  • Fix configuration.adoc respectively for a new endpoint bean name logic
  • In the end the new logic in the AbstractMethodAnnotationPostProcessor
    is similar to XML parsers: we feed annotation attributes to the
    AbstractStandardMessageHandlerFactoryBean impls

Fixes #3844

* Make `MessagingAnnotationPostProcessor` as a `BeanDefinitionRegistryPostProcessor`
to process bean definitions as early as possible and register respective messaging
components at that early phase
* Make bean definitions parsing logic optional for AOT and native mode since beans
have bean parsed during AOT building phase
* Introduce a `BeanDefinitionPropertiesMapper` for easier mapping
of the annotation attributes to the target `BeanDefinition`
* Remove `@Bean`-related logic from method parsing process
* Change the logic for `@Bean`-based endpoint bean names:
since we don't deal with methods on the bean definition phase, then method name
does not make sense.
It even may mislead if we `@Bean` name is based on a method by default, so we end up
with duplicated word in the target endpoint bean name.
Now we don't
* Fix `configuration.adoc` respectively for a new endpoint bean name logic
* In the end the new logic in the `AbstractMethodAnnotationPostProcessor`
is similar to XML parsers: we feed annotation attributes to the
`AbstractStandardMessageHandlerFactoryBean` impls

Poller poller = MessagingAnnotationUtils.resolveAttribute(annotations, "poller", Poller.class);
Reactive reactive = MessagingAnnotationUtils.resolveAttribute(annotations, "reactive", Reactive.class);
Assert.state(reactive == null || poller == null, "The 'poller' and 'reactive' are mutually exclusive.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either "'poller' and 'reactive' are mutually exclusive." or "The 'poller' and 'reactive' attributes are mutually exclusive." Also should include the bean name.

AbstractSimpleMessageHandlerFactoryBean.class)
&& !RouterFactoryBean.class.isAssignableFrom(handlerBeanClass)) {

applyAdviceChainIfAny(handlerBeanDefinition, annotations);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we doing this here - this will add all the advices to the handler - the CEFB (which also gets the full advice chain) selectively applies advices to the handler.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the comment exactly in that ConsumerEndpointFactoryBean.adviceChain():

 *  ARPMHs advise the handleRequestMessage method internally and already have the advice chain injected.
*  So we only advise handlers that are not reply-producing.

so, we don't set an adviceChain to the AbstractReplyProducingMessageHandler, neither from XML parser, nor Java DSL - ConsumerEndpointSpec.doGet().

We may revise it though, but I guess there was a reason why you implemented that way in the XML parser day first.
Different issue either way.

For example, the `SourcePollingChannelAdapter` endpoint for the `consoleSource()` definition <<annotations_on_beans,shown earlier>> gets a bean name of `myFlowConfiguration.consoleSource.inboundChannelAdapter`.
* The `AbstractEndpoint` bean name is generated with the following pattern: `[@Bean name].[decapitalizedAnnotationClassShortName]`.
For example, the `SourcePollingChannelAdapter` endpoint for the `consoleSource()` definition <<annotations_on_beans,shown earlier>> gets a bean name of `consoleSource.inboundChannelAdapter`.
Unlike with POJO methods the bean method name is not included into an endpoint bean name.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Unlike with POJO methods the bean method name is not included into an endpoint bean name.
Unlike with POJO methods, the bean method name is not included in the endpoint bean name.

@garyrussell garyrussell merged commit ca138c0 into main Aug 22, 2022
@artembilan artembilan deleted the GH-3844 branch December 12, 2022 20:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A BeanPostProcessor should not create bean definitions
2 participants