-
Notifications
You must be signed in to change notification settings - Fork 41.4k
Add support for RabbitMQ AMQP 1.0 #46608
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
Open
eddumelendez
wants to merge
9
commits into
spring-projects:main
Choose a base branch
from
eddumelendez:rabbitmq-amqp
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
91b9044
Add support for Rabbitmq AMQP 1.0
eddumelendez 02ba888
Add smoke test for RabbitMQ AMQP 1.0
eddumelendez 93d232d
Fix checks
eddumelendez 6572c36
Fix comments
eddumelendez a3913a1
Fix format
eddumelendez f983ae2
Autoconfigure only AMQP 1.0 or 0.9
eddumelendez db45892
Add new starter for rabbitmq 0.9
eddumelendez b6ec014
Use new starter
eddumelendez 58692fb
Update smoke test rabbit amqp
eddumelendez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...in/java/org/springframework/boot/amqp/autoconfigure/AmqpEnvironmentBuilderCustomizer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2012-present the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.boot.amqp.autoconfigure; | ||
|
||
import com.rabbitmq.client.amqp.Environment; | ||
import com.rabbitmq.client.amqp.impl.AmqpEnvironmentBuilder; | ||
|
||
/** | ||
* Callback interface that can be implemented by beans wishing to customize the | ||
* auto-configured {@link Environment} that is created by an | ||
* {@link AmqpEnvironmentBuilder}. | ||
* | ||
* @author Eddú Meléndez | ||
* @since 4.0.0 | ||
*/ | ||
@FunctionalInterface | ||
public interface AmqpEnvironmentBuilderCustomizer { | ||
|
||
/** | ||
* Customize the {@code AmqpEnvironmentBuilder}. | ||
* @param builder the builder to customize | ||
*/ | ||
void customize(AmqpEnvironmentBuilder builder); | ||
|
||
} |
136 changes: 136 additions & 0 deletions
136
...rc/main/java/org/springframework/boot/amqp/autoconfigure/RabbitAmqpAutoConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
/* | ||
* Copyright 2012-present the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.boot.amqp.autoconfigure; | ||
|
||
import com.rabbitmq.client.amqp.Connection; | ||
import com.rabbitmq.client.amqp.CredentialsProvider; | ||
import com.rabbitmq.client.amqp.Environment; | ||
import com.rabbitmq.client.amqp.impl.AmqpEnvironmentBuilder; | ||
import com.rabbitmq.client.amqp.impl.AmqpEnvironmentBuilder.EnvironmentConnectionSettings; | ||
|
||
import org.springframework.amqp.rabbit.config.ContainerCustomizer; | ||
import org.springframework.amqp.rabbit.retry.MessageRecoverer; | ||
import org.springframework.amqp.rabbitmq.client.AmqpConnectionFactory; | ||
import org.springframework.amqp.rabbitmq.client.RabbitAmqpAdmin; | ||
import org.springframework.amqp.rabbitmq.client.RabbitAmqpTemplate; | ||
import org.springframework.amqp.rabbitmq.client.SingleAmqpConnectionFactory; | ||
import org.springframework.amqp.rabbitmq.client.config.RabbitAmqpListenerContainerFactory; | ||
import org.springframework.amqp.rabbitmq.client.listener.RabbitAmqpListenerContainer; | ||
import org.springframework.amqp.support.converter.MessageConverter; | ||
import org.springframework.beans.factory.ObjectProvider; | ||
import org.springframework.boot.amqp.autoconfigure.RabbitConnectionDetails.Address; | ||
import org.springframework.boot.autoconfigure.AutoConfiguration; | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.boot.context.properties.PropertyMapper; | ||
import org.springframework.boot.ssl.SslBundles; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
/** | ||
* {@link EnableAutoConfiguration Auto-configuration} for {@link RabbitAmqpTemplate}. | ||
* | ||
* @author Eddú Meléndez | ||
* @since 4.0.0 | ||
*/ | ||
@AutoConfiguration(before = RabbitAutoConfiguration.class) | ||
@ConditionalOnClass({ RabbitAmqpTemplate.class, Connection.class }) | ||
@EnableConfigurationProperties(RabbitProperties.class) | ||
public final class RabbitAmqpAutoConfiguration { | ||
|
||
private final RabbitProperties properties; | ||
|
||
RabbitAmqpAutoConfiguration(RabbitProperties properties) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need to look into a separate |
||
this.properties = properties; | ||
} | ||
|
||
@Bean | ||
@ConditionalOnMissingBean | ||
RabbitConnectionDetails rabbitConnectionDetails(ObjectProvider<SslBundles> sslBundles) { | ||
return new PropertiesRabbitConnectionDetails(this.properties, sslBundles.getIfAvailable()); | ||
} | ||
|
||
@Bean(name = "rabbitListenerContainerFactory") | ||
@ConditionalOnMissingBean(name = "rabbitListenerContainerFactory") | ||
RabbitAmqpListenerContainerFactory rabbitAmqpListenerContainerFactory(AmqpConnectionFactory connectionFactory, | ||
ObjectProvider<ContainerCustomizer<RabbitAmqpListenerContainer>> amqpContainerCustomizer, | ||
ObjectProvider<RabbitRetryTemplateCustomizer> retryTemplateCustomizers, | ||
ObjectProvider<MessageRecoverer> messageRecoverer) { | ||
RabbitAmqpListenerContainerFactory factory = new RabbitAmqpListenerContainerFactory(connectionFactory); | ||
amqpContainerCustomizer.ifUnique(factory::setContainerCustomizer); | ||
|
||
RabbitProperties.AmqpContainer configuration = this.properties.getListener().getSimple(); | ||
factory.setObservationEnabled(configuration.isObservationEnabled()); | ||
return factory; | ||
} | ||
|
||
@Bean | ||
@ConditionalOnMissingBean | ||
Environment rabbitAmqpEnvironment(RabbitConnectionDetails connectionDetails, | ||
ObjectProvider<AmqpEnvironmentBuilderCustomizer> customizers, | ||
ObjectProvider<CredentialsProvider> credentialsProvider) { | ||
PropertyMapper map = PropertyMapper.get(); | ||
EnvironmentConnectionSettings environmentConnectionSettings = new AmqpEnvironmentBuilder().connectionSettings(); | ||
Address address = connectionDetails.getFirstAddress(); | ||
map.from(address::host).whenNonNull().to(environmentConnectionSettings::host); | ||
map.from(address::port).to(environmentConnectionSettings::port); | ||
map.from(connectionDetails::getUsername).whenNonNull().to(environmentConnectionSettings::username); | ||
map.from(connectionDetails::getPassword).whenNonNull().to(environmentConnectionSettings::password); | ||
map.from(connectionDetails::getVirtualHost).whenNonNull().to(environmentConnectionSettings::virtualHost); | ||
map.from(credentialsProvider::getIfAvailable) | ||
.whenNonNull() | ||
.to(environmentConnectionSettings::credentialsProvider); | ||
|
||
AmqpEnvironmentBuilder builder = environmentConnectionSettings.environmentBuilder(); | ||
customizers.orderedStream().forEach((customizer) -> customizer.customize(builder)); | ||
return builder.build(); | ||
} | ||
|
||
@Bean | ||
@ConditionalOnMissingBean | ||
AmqpConnectionFactory amqpConnectionFactory(Environment environment) { | ||
return new SingleAmqpConnectionFactory(environment); | ||
} | ||
|
||
@Bean | ||
@ConditionalOnMissingBean | ||
RabbitAmqpTemplate rabbitAmqpTemplate(AmqpConnectionFactory connectionFactory, | ||
ObjectProvider<RabbitAmqpTemplateCustomizer> customizers, | ||
ObjectProvider<MessageConverter> messageConverter) { | ||
RabbitAmqpTemplate rabbitAmqpTemplate = new RabbitAmqpTemplate(connectionFactory); | ||
if (messageConverter.getIfAvailable() != null) { | ||
rabbitAmqpTemplate.setMessageConverter(messageConverter.getIfAvailable()); | ||
} | ||
RabbitProperties.Template templateProperties = this.properties.getTemplate(); | ||
|
||
PropertyMapper map = PropertyMapper.get(); | ||
map.from(templateProperties::getDefaultReceiveQueue).whenNonNull().to(rabbitAmqpTemplate::setReceiveQueue); | ||
map.from(templateProperties::getExchange).whenNonNull().to(rabbitAmqpTemplate::setExchange); | ||
map.from(templateProperties::getRoutingKey).to(rabbitAmqpTemplate::setRoutingKey); | ||
|
||
customizers.orderedStream().forEach((customizer) -> customizer.customize(rabbitAmqpTemplate)); | ||
return rabbitAmqpTemplate; | ||
} | ||
|
||
@Bean | ||
@ConditionalOnMissingBean | ||
RabbitAmqpAdmin rabbitAmqpAdmin(AmqpConnectionFactory connectionFactory) { | ||
return new RabbitAmqpAdmin(connectionFactory); | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
...c/main/java/org/springframework/boot/amqp/autoconfigure/RabbitAmqpTemplateCustomizer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2012-present the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.boot.amqp.autoconfigure; | ||
|
||
import org.springframework.amqp.rabbitmq.client.RabbitAmqpTemplate; | ||
|
||
/** | ||
* Callback interface that can be used to customize a {@link RabbitAmqpTemplate}. | ||
* | ||
* @author Eddú Meléndez | ||
* @since 4.0.0 | ||
*/ | ||
@FunctionalInterface | ||
public interface RabbitAmqpTemplateCustomizer { | ||
|
||
/** | ||
* Callback to customize a {@link RabbitAmqpTemplate} instance. | ||
* @param rabbitAmqpTemplate the rabbitAmqpTemplate to customize | ||
*/ | ||
void customize(RabbitAmqpTemplate rabbitAmqpTemplate); | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...esources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
org.springframework.boot.amqp.autoconfigure.RabbitAmqpAutoConfiguration | ||
org.springframework.boot.amqp.autoconfigure.RabbitAutoConfiguration | ||
org.springframework.boot.amqp.autoconfigure.health.RabbitHealthContributorAutoConfiguration | ||
org.springframework.boot.amqp.autoconfigure.metrics.RabbitMetricsAutoConfiguration |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.