Skip to content

Provide auto-configuration for spring-rabbit-stream #27480

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

Closed
wants to merge 7 commits into from

Conversation

garyrussell
Copy link
Contributor

  • new container factory (not in existing hierarchy)
  • also add ContainerCustomizer to other factories

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 23, 2021
@@ -1416,13 +1423,20 @@ bom {
]
}
}
library("Rabbit AMQP Client", "5.13.0") {
library("RabbitMQ AMQP Client", "5.13.0") {
Copy link
Member

Choose a reason for hiding this comment

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

This will result in a breaking change to the version property. It's rabbit-amqp-client.version at the moment and this will change it to rabbitmq-amqp-client.version. I'd prefer to leave it unchanged, but if we want to change it, it should be done in a separate issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's fine; I just wanted to make it consistent; will revert.

@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(EnableRabbit.class)
@ConditionalOnProperty(prefix = "spring.rabbitmq.listener", name = "type", havingValue = "stream")
public class RabbitStreamAutoConfiguration {
Copy link
Member

Choose a reason for hiding this comment

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

We only name classes …AutoConfiguration if they're listed under the EnableAutoConfiguration key in spring.factories. This should be named RabbitStreamConfiguration or similar and should be package-private.

*
* @author Gary Russell
*/
@ExtendWith(OutputCaptureExtension.class)
Copy link
Member

@wilkinsona wilkinsona Jul 23, 2021

Choose a reason for hiding this comment

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

Is this needed? I can't see the captured output being used anywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy/paste artifact 😦

group("com.rabbitmq") {
modules = [
"amqp-client"
]
}
}
library("RabbitMQ Stream Client", "0.2.0-SNAPSHOT") {
Copy link
Member

@wilkinsona wilkinsona Jul 23, 2021

Choose a reason for hiding this comment

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

Is there an ETA for this having a tagged release? We don't want to be on a snapshot for too long and also wouldn't want to have to revert if the release isn't available before our next milestone.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will ask them when it is expected to be released, spring-rabbit-stream 2.4.0-M1 uses 0.1.0 (not a snapshot), but this needs a new feature in 0.2.0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Excellent. Given that it's not long, let's wait till the release rather than adding the Sonatype snapshot repo.

@@ -58,6 +58,7 @@ dependencies {
optional("org.apache.commons:commons-dbcp2")
optional("org.apache.httpcomponents.client5:httpclient5")
optional("org.apache.kafka:kafka-streams")
optional("org.apache.qpid:proton-j")
Copy link
Member

@wilkinsona wilkinsona Jul 26, 2021

Choose a reason for hiding this comment

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

I'm struggling to spot why this is needed so I tried removing it. Everything compiled cleanly. If it isn't needed we can get rid of the dependency management too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could move it to testImplementation but the stream-client is practically unusable without it; Spring Initializr would have to add it anyway - I don't know why it is not a transitive dependency of the client. I can start a discussion with them.

...
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.rabbitmq.stream.Environment]: Factory method 'rabbitStreamEnvironment' threw exception; nested exception is java.lang.NoClassDefFoundError: org/apache/qpid/proton/amqp/messaging/Section
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
	... 128 more
Caused by: java.lang.NoClassDefFoundError: org/apache/qpid/proton/amqp/messaging/Section

Copy link
Member

Choose a reason for hiding this comment

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

Yes, please. I'd rather it just comes in transitively than us having to manage the version and keep things in sync.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@wilkinsona wilkinsona added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 26, 2021
@wilkinsona wilkinsona added this to the 2.6.x milestone Jul 26, 2021
@wilkinsona wilkinsona added the status: on-hold We can't start working on this issue yet label Jul 26, 2021
@snicoll snicoll removed the status: on-hold We can't start working on this issue yet label Jul 28, 2021
@snicoll snicoll changed the title Initial Auto Config for spring-rabbit-stream Auto-Configuration Support for spring-rabbit-stream Aug 6, 2021
@wilkinsona wilkinsona self-assigned this Aug 10, 2021
Copy link
Member

@wilkinsona wilkinsona left a comment

Choose a reason for hiding this comment

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

Thanks for the updates, Gary. I've left a few more comments.

I'm not sure about the need for the changes to RabbitAnnotationDrivenConfiguration. They feel separate to adding spring-rabbit-stream support. If that's right, I'd prefer that we make them in a separate enhancement.

@@ -1128,4 +1165,48 @@ private boolean determineSslEnabled(boolean sslEnabled) {

}

public static final class Stream {

private String host = "localhost";
Copy link
Member

Choose a reason for hiding this comment

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

This property needs some javadoc that'll be captured in the configuration property metadata.


private String host = "localhost";

private int port = DEFAULT_STREAM_PORT;
Copy link
Member

Choose a reason for hiding this comment

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

This property needs some javadoc that'll be captured in the configuration property metadata.


private int port = DEFAULT_STREAM_PORT;

private String userName;
Copy link
Member

@wilkinsona wilkinsona Aug 10, 2021

Choose a reason for hiding this comment

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

This property needs some javadoc that'll be captured in the configuration property metadata.


private String userName;

private String password;
Copy link
Member

Choose a reason for hiding this comment

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

This property needs some javadoc that'll be captured in the configuration property metadata.

@Bean(name = "rabbitListenerContainerFactory")
@ConditionalOnMissingBean(name = "rabbitListenerContainerFactory")
StreamRabbitListenerContainerFactory streamRabbitListenerContainerFactory(Environment rabbitStreamEnvironment,
RabbitProperties properties, ObjectProvider<ConsumerCustomizer> consumerCustomizers,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
RabbitProperties properties, ObjectProvider<ConsumerCustomizer> consumerCustomizers,
RabbitProperties properties, ObjectProvider<ConsumerCustomizer> consumerCustomizer,

I think this makes sense given that the setter is singular.

Comment on lines 57 to 59
if (containerCustomizers.getIfUnique() != null) {
factory.setContainerCustomizer(containerCustomizers.getIfUnique());
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (containerCustomizers.getIfUnique() != null) {
factory.setContainerCustomizer(containerCustomizers.getIfUnique());
}
containerCustomizer.ifUnique(factory::setContainerCustomizer);

@@ -871,6 +894,20 @@ public void setMissingQueuesFatal(boolean missingQueuesFatal) {

}

public static class StreamContainer extends BaseContainer {

boolean nativeListener;
Copy link
Member

Choose a reason for hiding this comment

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

This property needs some javadoc that'll be captured in the configuration property metadata.

@ConditionalOnMissingBean(name = "rabbitListenerContainerFactory")
StreamRabbitListenerContainerFactory streamRabbitListenerContainerFactory(Environment rabbitStreamEnvironment,
RabbitProperties properties, ObjectProvider<ConsumerCustomizer> consumerCustomizers,
ObjectProvider<ContainerCustomizer<StreamListenerContainer>> containerCustomizers) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
ObjectProvider<ContainerCustomizer<StreamListenerContainer>> containerCustomizers) {
ObjectProvider<ContainerCustomizer<StreamListenerContainer>> containerCustomizer) {

I think this makes sense given that the setter is singular.

Comment on lines 38 to 43
* @since 2.6
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(EnableRabbit.class)
@ConditionalOnProperty(prefix = "spring.rabbitmq.listener", name = "type", havingValue = "stream")
public class RabbitStreamConfiguration {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @since 2.6
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(EnableRabbit.class)
@ConditionalOnProperty(prefix = "spring.rabbitmq.listener", name = "type", havingValue = "stream")
public class RabbitStreamConfiguration {
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(EnableRabbit.class)
@ConditionalOnProperty(prefix = "spring.rabbitmq.listener", name = "type", havingValue = "stream")
class RabbitStreamConfiguration {

* @since 2.6
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(EnableRabbit.class)
Copy link
Member

Choose a reason for hiding this comment

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

Does this need to be conditional on StreamRabbitListenerContainerFactory or similar as well?

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Aug 10, 2021
@@ -1646,11 +1653,12 @@ bom {
]
}
}
library("Spring AMQP", "2.4.0-M1") {
library("Spring AMQP", "2.4.0-SNAPSHOT") {
Copy link
Member

Choose a reason for hiding this comment

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

When's 2.4.0-M2 due? I can't see it in the release calendar at the moment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aug 16 - scheduled.

@wilkinsona wilkinsona removed the status: waiting-for-feedback We need additional information before we can continue label Aug 11, 2021
wilkinsona pushed a commit that referenced this pull request Aug 11, 2021
@wilkinsona wilkinsona changed the title Auto-Configuration Support for spring-rabbit-stream Provide auto-configuration for spring-rabbit-stream Aug 11, 2021
@wilkinsona wilkinsona removed this from the 2.6.x milestone Aug 11, 2021
@wilkinsona wilkinsona added this to the 2.6.0-M2 milestone Aug 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants