-
Notifications
You must be signed in to change notification settings - Fork 41.6k
Spring AMQP: Support Both Container Types #9055
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
Conversation
Resolves: spring-projects#9041 Spring AMQP 2.0 introduced a new container type. Add support for auto configuration - select container type and separate discrete properties.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! I've some questions, see individual comments.
public enum ContainerType { | ||
|
||
/** | ||
* SimpleMessageListenerContainer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we expand that doc a little? That is showing up in IDEs and being able to understand the benefit would help.
@ConditionalOnMissingBean | ||
public SimpleRabbitListenerContainerFactoryConfigurer rabbitListenerContainerFactoryConfigurer() { | ||
SimpleRabbitListenerContainerFactoryConfigurer configurer = new SimpleRabbitListenerContainerFactoryConfigurer(); | ||
public RabbitListenerContainerFactoryConfigurer rabbitListenerContainerFactoryConfigurer() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd prefer two configurer implementations with dedicated types and a base class. I understand that's quite a lot of code but that probably translates well with what that thing is configuring.
@ConditionalOnMissingBean(name = "rabbitListenerContainerFactory") | ||
public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory( | ||
SimpleRabbitListenerContainerFactoryConfigurer configurer, | ||
public AbstractRabbitListenerContainerFactory<?> rabbitListenerContainerFactory( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
II think I'd prefer two definitions with a @ConditionalOnProperty
that translates that if/else below. We prefer to expose the concrete type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started down that route, but it didn't work as I expected.
I had @ConditionalOnProperty( ... havingValue = "simple")
and @ConditionalOnProperty( ... havingValue = "direct")
...it didn't work without explicitly setting the property - but I now see there's a matchIfMissing
attribute ... doh.
Will rework.
|
||
public static class Listener { | ||
|
||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation keys do not start with "The", "A", etc.
private final ListenerRetry retry = new ListenerRetry(); | ||
|
||
@NestedConfigurationProperty | ||
private final SimpleContainer simple = new SimpleContainer(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So Direct only supports one property? I am a bit confused. The hierarchy of properties are becoming quite complex now so I am wondering if we should create those two namespaces at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@snicoll The remaining properties (in Listener
) are common to both containers (on the abstract container). The SMLC has 3 properties that are not available with the DMLC and it has one property that's not available on the SMLC. I don't mind having them at the top Listener
level and simply ignoring those that don't apply, based on the containerType
; it would certainly be better for backwards compatibility. I thought you preferred this hierarchical approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK I get it now. The problem is that there are other nested namespaces that are common. So you have retry
that is, and simple
and direct
, at the same level, that are specific.
I indeed prefer the hierarchical approach but the hierarchy is kind of wrong if you ask me. I have no idea how to fix it though so please do not act on it until we figure it out.
- Remove listener type hierarcy in properties - Add configurer class hierarchy and conditional beans
Add support for auto configuration - select container type and separate discrete properties. See gh-9055
* pr/9055: Remove deprecated spring.rabbitmq.listener.* properties Polish "Support direct AMQP container" Support direct AMQP container
Thanks @garyrussell - I decided to go a different route with dedicated namespace for the two container types (and a early deprecation of the existing keys in 1.5). I've also simplified the configurer auto-config as we want both of them to be present regardless of the container type (you are free to create as many containers as you want after all). |
|
||
/** | ||
* Container type. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know all of the intimate details, but the description above for ContainerType.SIMPLE
is that it is the legacy container type. Wouldn't it be better to default to the non-legacy type with the new major version of Spring Boot (and Spring AMQP)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, it's not black and white - each container has certain pros and cons. I feel that changing the container type without the user explicitly choosing to do so could cause unexpected problems for users.
I prefer that the user explicitly opt-in to using the new container. Documentation here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @garyrussell - We've created a dedicated issue to figure this out. Can you please move your comment over there? #9173
Resolves: #9041
Spring AMQP 2.0 introduced a new container type.
Add support for auto configuration - select container type and separate discrete properties.