Allow to easily customize ListenerContainerFactory
Previously, if one wants to create a custom `JmsListenerContainerFactory` or `RabbitListenerContainerFactory`, a bunch of code from the auto- configuration must be duplicated. This commit introduces two services to configure such factory for JMS and AMQP with the same sensible defaults that were applied by the auto-configufrations. Closes gh-5138
This commit is contained in:
@@ -3489,6 +3489,44 @@ The following component creates a listener endpoint on the `someQueue` destinati
|
||||
TIP: Check {spring-javadoc}/jms/annotation/EnableJms.{dc-ext}[the Javadoc of `@EnableJms`] for
|
||||
more details.
|
||||
|
||||
If you need to create more `JmsListenerContainerFactory` instances or if you want to override
|
||||
the default, Spring Boot provides a `JmsListenerContainerFactoryConfigurer` that you can use
|
||||
to initialize a `DefaultJmsListenerContainerFactory` with the same settings as the one that
|
||||
is auto-configured.
|
||||
|
||||
For instance, the following exposes another factory that uses a specific `MessageConverter`:
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
@Configuration
|
||||
static class JmsConfiguration {
|
||||
|
||||
@Bean
|
||||
public DefaultJmsListenerContainerFactory myFactory(
|
||||
JmsListenerContainerFactoryConfigurer configurer) {
|
||||
DefaultJmsListenerContainerFactory factory = configurer
|
||||
.createJmsListenerContainerFactory(connectionFactory());
|
||||
factory.setMessageConverter(myMessageConverter());
|
||||
return factory;
|
||||
}
|
||||
|
||||
}
|
||||
----
|
||||
|
||||
That you can use in any `@JmsListener`-annotated method as follows:
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
@Component
|
||||
public class MyBean {
|
||||
|
||||
@JmsListener(destination = "someQueue", **containerFactory="myFactory"**)
|
||||
public void processMessage(String content) {
|
||||
// ...
|
||||
}
|
||||
|
||||
}
|
||||
----
|
||||
|
||||
|
||||
[[boot-features-amqp]]
|
||||
@@ -3585,6 +3623,44 @@ The following component creates a listener endpoint on the `someQueue` queue:
|
||||
TIP: Check {spring-amqp-javadoc}/rabbit/annotation/EnableRabbit.{dc-ext}[the Javadoc of `@EnableRabbit`]
|
||||
for more details.
|
||||
|
||||
If you need to create more `RabbitListenerContainerFactory` instances or if you want to override
|
||||
the default, Spring Boot provides a `RabbitListenerContainerFactoryConfigurer` that you can use
|
||||
to initialize a `SimpleRabbitListenerContainerFactory` with the same settings as the one that
|
||||
is auto-configured.
|
||||
|
||||
For instance, the following exposes another factory that uses a specific `MessageConverter`:
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
@Configuration
|
||||
static class RabbitConfiguration {
|
||||
|
||||
@Bean
|
||||
public SimpleRabbitListenerContainerFactory myFactory(
|
||||
RabbitListenerContainerFactoryConfigurer configurer) {
|
||||
SimpleRabbitListenerContainerFactory factory = configurer
|
||||
.createRabbitListenerContainerFactory(connectionFactory());
|
||||
factory.setMessageConverter(myMessageConverter());
|
||||
return factory;
|
||||
}
|
||||
|
||||
}
|
||||
----
|
||||
|
||||
That you can use in any `@RabbitListener`-annotated method as follows:
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
@Component
|
||||
public class MyBean {
|
||||
|
||||
@RabbitListener(queues = "someQueue", **containerFactory="myFactory"**)
|
||||
public void processMessage(String content) {
|
||||
// ...
|
||||
}
|
||||
|
||||
}
|
||||
----
|
||||
|
||||
|
||||
[[boot-features-email]]
|
||||
|
||||
Reference in New Issue
Block a user