mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-17 12:09:16 +00:00
Add AMQP 1.0 generic auto-configuration
This commit adds auto-configuration for the generic AMQP 1.0 client in Spring AMQP 4.1, using Qpid ProtonJ. Support for connection factory, client and listener endpoints are available. The "spring.amqp" namespace exposes settings to connect to an AMQP 1.0 compliant broker and customize client and listeners settings. Docker compose and testcontainers support using RabbitMQ, ActiveMQ, and Artemis have been added too. Closes gh-49678
This commit is contained in:
@@ -94,6 +94,7 @@ dependencies {
|
||||
implementation(project(path: ":loader:spring-boot-loader-tools"))
|
||||
implementation(project(path: ":module:spring-boot-actuator"))
|
||||
implementation(project(path: ":module:spring-boot-actuator-autoconfigure"))
|
||||
implementation(project(path: ":module:spring-boot-amqp"))
|
||||
implementation(project(path: ":module:spring-boot-cache"))
|
||||
implementation(project(path: ":module:spring-boot-cache-test"))
|
||||
implementation(project(path: ":module:spring-boot-data-cassandra"))
|
||||
|
||||
@@ -1716,13 +1716,13 @@
|
||||
* xref:reference:messaging/amqp.adoc#messaging.amqp.rabbitmq[#features.messaging.amqp.rabbit]
|
||||
* xref:reference:messaging/amqp.adoc#messaging.amqp.rabbitmq[#messaging.amqp.rabbit]
|
||||
* xref:reference:messaging/amqp.adoc#messaging.amqp.rabbitmq[#messaging.amqp.rabbitmq]
|
||||
* xref:reference:messaging/amqp.adoc#messaging.amqp.receiving[#boot-features-using-amqp-receiving]
|
||||
* xref:reference:messaging/amqp.adoc#messaging.amqp.receiving[#features.messaging.amqp.receiving]
|
||||
* xref:reference:messaging/amqp.adoc#messaging.amqp.receiving[#messaging.amqp.receiving]
|
||||
* xref:reference:messaging/amqp.adoc#messaging.amqp.sending-stream[#messaging.amqp.sending-stream]
|
||||
* xref:reference:messaging/amqp.adoc#messaging.amqp.sending[#boot-features-using-amqp-sending]
|
||||
* xref:reference:messaging/amqp.adoc#messaging.amqp.sending[#features.messaging.amqp.sending]
|
||||
* xref:reference:messaging/amqp.adoc#messaging.amqp.sending[#messaging.amqp.sending]
|
||||
* xref:reference:messaging/amqp.adoc#messaging.amqp.rabbitmq.receiving[#boot-features-using-amqp-receiving]
|
||||
* xref:reference:messaging/amqp.adoc#messaging.amqp.rabbitmq.receiving[#features.messaging.amqp.receiving]
|
||||
* xref:reference:messaging/amqp.adoc#messaging.amqp.rabbitmq.receiving[#messaging.amqp.receiving]
|
||||
* xref:reference:messaging/amqp.adoc#messaging.amqp.rabbitmq.sending-stream[#messaging.amqp.sending-stream]
|
||||
* xref:reference:messaging/amqp.adoc#messaging.amqp.rabbitmq.sending[#boot-features-using-amqp-sending]
|
||||
* xref:reference:messaging/amqp.adoc#messaging.amqp.rabbitmq.sending[#features.messaging.amqp.sending]
|
||||
* xref:reference:messaging/amqp.adoc#messaging.amqp.rabbitmq.sending[#messaging.amqp.sending]
|
||||
* xref:reference:messaging/amqp.adoc#messaging.amqp[#boot-features-amqp]
|
||||
* xref:reference:messaging/amqp.adoc#messaging.amqp[#features.messaging.amqp]
|
||||
* xref:reference:messaging/amqp.adoc#messaging.amqp[#messaging.amqp]
|
||||
|
||||
+3
@@ -86,6 +86,9 @@ The following service connections are currently supported:
|
||||
| javadoc:org.springframework.boot.activemq.autoconfigure.ActiveMQConnectionDetails[]
|
||||
| Containers named "symptoma/activemq", "apache/activemq-classic" or "apache/activemq"
|
||||
|
||||
| javadoc:org.springframework.boot.amqp.autoconfigure.AmqpConnectionDetails[]
|
||||
| Containers named "rabbitmq" or "apache/activemq-classic" or "apache/activemq-artemis"
|
||||
|
||||
| javadoc:org.springframework.boot.artemis.autoconfigure.ArtemisConnectionDetails[]
|
||||
| Containers named "apache/activemq-artemis" or "apache/artemis"
|
||||
|
||||
|
||||
+80
-9
@@ -3,7 +3,78 @@
|
||||
|
||||
The Advanced Message Queuing Protocol (AMQP) is a platform-neutral, wire-level protocol for message-oriented middleware.
|
||||
The Spring AMQP project applies core Spring concepts to the development of AMQP-based messaging solutions.
|
||||
Spring Boot offers several conveniences for working with AMQP through RabbitMQ, including the `spring-boot-starter-rabbitmq` starter.
|
||||
Spring Boot offers several conveniences for working with AMQP: generic AMQP 1.0 support is provided by the `spring-boot-starter-amqp` starter while specific RabbitMQ support is available via the `spring-boot-starter-rabbitmq` starter.
|
||||
|
||||
|
||||
|
||||
[[messaging.amqp.generic]]
|
||||
== Generic AMQP 1.0 Support
|
||||
|
||||
AMQP 1.0 is supported by several brokers and messaging services beyond RabbitMQ, including ActiveMQ, Azure Service Bus, and others.
|
||||
Spring AMQP provides {url-spring-amqp-docs}/amqp10-client.html[generic support for AMQP 1.0] via `org.springframework.amqp:spring-amqp-client` that is based on the https://github.com/apache/qpid-protonj2/blob/main/protonj2-client/README.md[Qpid ProtonJ2 Client Library].
|
||||
|
||||
AMQP configuration is controlled by external configuration properties in `+spring.amqp.*+`.
|
||||
For example, you might declare the following in your configuration:
|
||||
|
||||
[configprops,yaml]
|
||||
----
|
||||
spring:
|
||||
amqp:
|
||||
host: "localhost"
|
||||
port: 5672
|
||||
username: "admin"
|
||||
password: "secret"
|
||||
----
|
||||
|
||||
To configure javadoc:org.apache.qpid.protonj2.client.ConnectionOptions[connection options] of the auto-configured javadoc:org.springframework.amqp.client.AmqpConnectionFactory[], define a javadoc:org.springframework.boot.amqp.autoconfigure.ConnectionOptionsCustomizer[] bean.
|
||||
|
||||
[[messaging.amqp.generic.sending]]
|
||||
=== Sending a Message
|
||||
|
||||
Spring's javadoc:org.springframework.amqp.client.AmqpClient[] is auto-configured, and you can autowire it directly into your own beans, as shown in the following example:
|
||||
|
||||
include-code::MyBean[]
|
||||
|
||||
If a javadoc:org.springframework.amqp.support.converter.MessageConverter[] bean is defined, it is associated automatically with the auto-configured javadoc:org.springframework.amqp.client.AmqpClient[].
|
||||
If no such converter is defined and Jackson is available, javadoc:org.springframework.amqp.support.converter.JacksonJsonMessageConverter[] is used.
|
||||
|
||||
Client-specific settings can be configured as follows:
|
||||
|
||||
[configprops,yaml]
|
||||
----
|
||||
spring:
|
||||
amqp:
|
||||
client:
|
||||
default-to-address: "/queues/default_queue"
|
||||
completion-timeout: "500ms"
|
||||
----
|
||||
|
||||
To further configure the auto-configured javadoc:org.springframework.amqp.client.AmqpClient[], define a javadoc:org.springframework.boot.amqp.autoconfigure.AmqpClientCustomizer[] bean.
|
||||
|
||||
|
||||
|
||||
[[messaging.amqp.generic.receiving]]
|
||||
=== Receiving a Message
|
||||
|
||||
When the generic AMQP 1.0 infrastructure is present, any bean can be annotated with javadoc:org.springframework.amqp.client.annotation.AmqpListener[format=annotation] to create a listener endpoint.
|
||||
If no javadoc:org.springframework.amqp.client.config.MethodAmqpMessageListenerContainerFactory[] has been defined, a default one is automatically configured.
|
||||
If a javadoc:org.springframework.amqp.support.converter.MessageConverter[] or a javadoc:org.springframework.amqp.client.listener.AmqpListenerErrorHandler[] bean is defined, it is automatically associated with the default factory.
|
||||
|
||||
The following sample component creates a listener endpoint on the `/queues/someQueue` address:
|
||||
|
||||
include-code::MyBean[]
|
||||
|
||||
TIP: See javadoc:org.springframework.amqp.client.config.EnableAmqp[format=annotation] for more details.
|
||||
|
||||
If you need to create more javadoc:org.springframework.amqp.client.config.MethodAmqpMessageListenerContainerFactory[] instances or if you want to override the default, Spring Boot provides a javadoc:org.springframework.boot.amqp.autoconfigure.AmqpMessageListenerContainerFactoryConfigurer[] that you can use to initialize a javadoc:org.springframework.amqp.client.config.MethodAmqpMessageListenerContainerFactory[] with the same settings as the factory used by the auto-configuration.
|
||||
|
||||
For instance, the following configuration class exposes another factory that uses a specific javadoc:org.springframework.amqp.support.converter.MessageConverter[]:
|
||||
|
||||
include-code::custom/MyAmqpConfiguration[]
|
||||
|
||||
Then you can use the factory in any javadoc:org.springframework.amqp.client.annotation.AmqpListener[format=annotation]-annotated method, as follows:
|
||||
|
||||
include-code::custom/MyBean[]
|
||||
|
||||
|
||||
|
||||
@@ -49,8 +120,8 @@ TIP: See https://spring.io/blog/2010/06/14/understanding-amqp-the-protocol-used-
|
||||
|
||||
|
||||
|
||||
[[messaging.amqp.sending]]
|
||||
== Sending a Message
|
||||
[[messaging.amqp.rabbitmq.sending]]
|
||||
=== Sending a Message
|
||||
|
||||
Spring's javadoc:org.springframework.amqp.core.AmqpTemplate[] and javadoc:org.springframework.amqp.core.AmqpAdmin[] are auto-configured, and you can autowire them directly into your own beans, as shown in the following example:
|
||||
|
||||
@@ -82,8 +153,8 @@ If there's a bean of type javadoc:org.springframework.amqp.rabbit.support.microm
|
||||
|
||||
|
||||
|
||||
[[messaging.amqp.sending-stream]]
|
||||
== Sending a Message To A Stream
|
||||
[[messaging.amqp.rabbitmq.sending-stream]]
|
||||
=== Sending a Message To A Stream
|
||||
|
||||
To send a message to a particular stream, specify the name of the stream, as shown in the following example:
|
||||
|
||||
@@ -101,14 +172,14 @@ If you need to create more javadoc:org.springframework.rabbit.stream.producer.Ra
|
||||
|
||||
|
||||
|
||||
[[messaging.amqp.sending-stream.ssl]]
|
||||
=== SSL
|
||||
[[messaging.amqp.rabbitmq.sending-stream.ssl]]
|
||||
==== SSL
|
||||
To use SSL with RabbitMQ Streams, set configprop:spring.rabbitmq.stream.ssl.enabled[] to `true` or set configprop:spring.rabbitmq.stream.ssl.bundle[] to configure the xref:features/ssl.adoc#features.ssl.bundles[SSL bundle] to use.
|
||||
|
||||
|
||||
|
||||
[[messaging.amqp.receiving]]
|
||||
== Receiving a Message
|
||||
[[messaging.amqp.rabbitmq.receiving]]
|
||||
=== Receiving a Message
|
||||
|
||||
When the Rabbit infrastructure is present, any bean can be annotated with javadoc:org.springframework.amqp.rabbit.annotation.RabbitListener[format=annotation] to create a listener endpoint.
|
||||
If no javadoc:org.springframework.amqp.rabbit.listener.RabbitListenerContainerFactory[] has been defined, a default javadoc:org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory[] is automatically configured and you can switch to a direct container using the configprop:spring.rabbitmq.listener.type[] property.
|
||||
|
||||
+3
@@ -128,6 +128,9 @@ The following service connection factories are provided in the `spring-boot-test
|
||||
| javadoc:org.springframework.boot.activemq.autoconfigure.ActiveMQConnectionDetails[]
|
||||
| Containers named "symptoma/activemq" or javadoc:org.testcontainers.activemq.ActiveMQContainer[]
|
||||
|
||||
| javadoc:org.springframework.boot.amqp.autoconfigure.AmqpConnectionDetails[]
|
||||
| Containers of types javadoc:{url-testcontainers-rabbitmq-javadoc}/org.testcontainers.rabbitmq.RabbitMQContainer[] or avadoc:org.testcontainers.activemq.ActiveMQContainer[] or javadoc:org.testcontainers.activemq.ArtemisContainer[]
|
||||
|
||||
| javadoc:org.springframework.boot.artemis.autoconfigure.ArtemisConnectionDetails[]
|
||||
| Containers of type javadoc:org.testcontainers.activemq.ArtemisContainer[]
|
||||
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.docs.messaging.amqp.generic.receiving;
|
||||
|
||||
import org.springframework.amqp.client.annotation.AmqpListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class MyBean {
|
||||
|
||||
@AmqpListener(addresses = "/queues/someQueue")
|
||||
public void processMessage(String content) {
|
||||
// ...
|
||||
}
|
||||
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.docs.messaging.amqp.generic.receiving.custom;
|
||||
|
||||
import org.springframework.amqp.client.AmqpConnectionFactory;
|
||||
import org.springframework.amqp.client.config.MethodAmqpMessageListenerContainerFactory;
|
||||
import org.springframework.boot.amqp.autoconfigure.AmqpMessageListenerContainerFactoryConfigurer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
public class MyAmqpConfiguration {
|
||||
|
||||
@Bean
|
||||
public MethodAmqpMessageListenerContainerFactory myFactory(AmqpMessageListenerContainerFactoryConfigurer configurer,
|
||||
AmqpConnectionFactory connectionFactory) {
|
||||
MethodAmqpMessageListenerContainerFactory factory = new MethodAmqpMessageListenerContainerFactory(
|
||||
connectionFactory);
|
||||
configurer.configure(factory);
|
||||
factory.setMessageConverter(new MyMessageConverter());
|
||||
return factory;
|
||||
}
|
||||
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.docs.messaging.amqp.generic.receiving.custom;
|
||||
|
||||
import org.springframework.amqp.client.annotation.AmqpListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class MyBean {
|
||||
|
||||
@AmqpListener(addresses = "/queues/someQueue", containerFactory = "myFactory")
|
||||
public void processMessage(String content) {
|
||||
// ...
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.docs.messaging.amqp.receiving.custom;
|
||||
package org.springframework.boot.docs.messaging.amqp.generic.receiving.custom;
|
||||
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.core.MessageProperties;
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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.docs.messaging.amqp.generic.sending;
|
||||
|
||||
import org.springframework.amqp.client.AmqpClient;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class MyBean {
|
||||
|
||||
private final AmqpClient amqpClient;
|
||||
|
||||
public MyBean(AmqpClient amqpClient) {
|
||||
this.amqpClient = amqpClient;
|
||||
}
|
||||
|
||||
// @fold:on // ...
|
||||
public void sendMessage(String msg) {
|
||||
this.amqpClient.to("/queues/test").body(msg).send();
|
||||
}
|
||||
// @fold:off
|
||||
|
||||
}
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.docs.messaging.amqp.receiving;
|
||||
package org.springframework.boot.docs.messaging.amqp.rabbitmq.receiving;
|
||||
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.docs.messaging.amqp.receiving.custom;
|
||||
package org.springframework.boot.docs.messaging.amqp.rabbitmq.receiving.custom;
|
||||
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
+36
@@ -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.docs.messaging.amqp.rabbitmq.receiving.custom;
|
||||
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.core.MessageProperties;
|
||||
import org.springframework.amqp.support.converter.MessageConversionException;
|
||||
import org.springframework.amqp.support.converter.MessageConverter;
|
||||
|
||||
class MyMessageConverter implements MessageConverter {
|
||||
|
||||
@Override
|
||||
public Message toMessage(Object object, MessageProperties messageProperties) throws MessageConversionException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object fromMessage(Message message) throws MessageConversionException {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.docs.messaging.amqp.receiving.custom;
|
||||
package org.springframework.boot.docs.messaging.amqp.rabbitmq.receiving.custom;
|
||||
|
||||
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.docs.messaging.amqp.sending;
|
||||
package org.springframework.boot.docs.messaging.amqp.rabbitmq.sending;
|
||||
|
||||
import org.springframework.amqp.core.AmqpAdmin;
|
||||
import org.springframework.amqp.core.AmqpTemplate;
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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.docs.messaging.amqp.generic.receiving
|
||||
|
||||
import org.springframework.amqp.client.annotation.AmqpListener
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
@Component
|
||||
class MyBean {
|
||||
|
||||
@AmqpListener(addresses = ["/queues/someQueue"])
|
||||
fun processMessage(content: String?) {
|
||||
// ...
|
||||
}
|
||||
|
||||
}
|
||||
+39
@@ -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.docs.messaging.amqp.generic.receiving.custom
|
||||
|
||||
import org.springframework.amqp.client.AmqpConnectionFactory
|
||||
import org.springframework.amqp.client.config.MethodAmqpMessageListenerContainerFactory
|
||||
import org.springframework.boot.amqp.autoconfigure.AmqpMessageListenerContainerFactoryConfigurer
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
class MyAmqpConfiguration {
|
||||
|
||||
@Bean
|
||||
fun myFactory(
|
||||
configurer: AmqpMessageListenerContainerFactoryConfigurer,
|
||||
connectionFactory: AmqpConnectionFactory
|
||||
): MethodAmqpMessageListenerContainerFactory {
|
||||
val factory = MethodAmqpMessageListenerContainerFactory(connectionFactory)
|
||||
configurer.configure(factory)
|
||||
factory.setMessageConverter(MyMessageConverter())
|
||||
return factory
|
||||
}
|
||||
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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.docs.messaging.amqp.generic.receiving.custom
|
||||
|
||||
import org.springframework.amqp.client.annotation.AmqpListener
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
@Component
|
||||
class MyBean {
|
||||
|
||||
@AmqpListener(addresses = ["/queues/someQueue"], containerFactory = "myFactory")
|
||||
fun processMessage(content: String?) {
|
||||
// ...
|
||||
}
|
||||
|
||||
}
|
||||
+1
-2
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.docs.messaging.amqp.receiving.custom
|
||||
package org.springframework.boot.docs.messaging.amqp.generic.receiving.custom
|
||||
|
||||
import org.springframework.amqp.core.Message
|
||||
import org.springframework.amqp.core.MessageProperties
|
||||
@@ -31,4 +31,3 @@ internal class MyMessageConverter : MessageConverter {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.docs.messaging.amqp.generic.sending
|
||||
|
||||
import org.springframework.amqp.client.AmqpClient
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
@Component
|
||||
class MyBean(private val amqpClient: AmqpClient) {
|
||||
|
||||
// @fold:on // ...
|
||||
fun someOtherMethod(msg: String) {
|
||||
amqpClient.to("/queues/test").body(msg).send()
|
||||
}
|
||||
// @fold:off
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.docs.messaging.amqp.receiving
|
||||
package org.springframework.boot.docs.messaging.amqp.rabbitmq.receiving
|
||||
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener
|
||||
import org.springframework.stereotype.Component
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.docs.messaging.amqp.receiving.custom
|
||||
package org.springframework.boot.docs.messaging.amqp.rabbitmq.receiving.custom
|
||||
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener
|
||||
import org.springframework.stereotype.Component
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.docs.messaging.amqp.rabbitmq.receiving.custom
|
||||
|
||||
import org.springframework.amqp.core.Message
|
||||
import org.springframework.amqp.core.MessageProperties
|
||||
import org.springframework.amqp.support.converter.MessageConverter
|
||||
|
||||
internal class MyMessageConverter : MessageConverter {
|
||||
|
||||
override fun toMessage(`object`: Any, messageProperties: MessageProperties): Message {
|
||||
return Message(byteArrayOf())
|
||||
}
|
||||
|
||||
override fun fromMessage(message: Message): Any {
|
||||
return Any()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.docs.messaging.amqp.receiving.custom
|
||||
package org.springframework.boot.docs.messaging.amqp.rabbitmq.receiving.custom
|
||||
|
||||
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory
|
||||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.docs.messaging.amqp.sending
|
||||
package org.springframework.boot.docs.messaging.amqp.rabbitmq.sending
|
||||
|
||||
import org.springframework.amqp.core.AmqpAdmin
|
||||
import org.springframework.amqp.core.AmqpTemplate
|
||||
Reference in New Issue
Block a user