When
ActiveMQ
is available on the classpath, Spring Boot can
also configure a
ConnectionFactory
. If the broker is present, an embedded broker is
automatically started and configured (provided no broker URL is specified through
configuration).
|
Note
|
If you use
spring-boot-starter-activemq
, the necessary dependencies to connect or
embed an ActiveMQ instance are provided, as is the Spring infrastructure to integrate with
JMS.
|
ActiveMQ configuration is controlled by external configuration properties in
spring.activemq.*
. For example, you might declare the following section in
application.properties
:
spring.activemq.broker-url=tcp://192.168.1.210:9876
spring.activemq.user=admin
spring.activemq.password=secret
By default, a
CachingConnectionFactory
wraps the native
ConnectionFactory
with
sensible settings that you can control by external configuration properties in
spring.jms.*
:
spring.jms.cache.session-cache-size=5
If you’d rather use native pooling, you can do so by adding a dependency to
org.messaginghub:pooled-jms
and configuring the
JmsPoolConnectionFactory
accordingly,
as shown in the following example:
spring.activemq.pool.enabled=true
spring.activemq.pool.max-connections=50
|
Tip
|
See
ActiveMQProperties
for more of the supported options. You can also register an arbitrary number of beans
that implement
ActiveMQConnectionFactoryCustomizer
for more advanced customizations.
|
By default, ActiveMQ creates a destination if it does not yet exist so that destinations
are resolved against their provided names.
Spring Boot can auto-configure a
ConnectionFactory
when it detects that
Artemis
is available on the classpath. If the broker
is present, an embedded broker is automatically started and configured (unless the mode
property has been explicitly set). The supported modes are
embedded
(to make explicit
that an embedded broker is required and that an error should occur if the broker is not
available on the classpath) and
native
(to connect to a broker using the
netty
transport protocol). When the latter is configured, Spring Boot configures a
ConnectionFactory
that connects to a broker running on the local machine with the
default settings.
|
Note
|
If you use
spring-boot-starter-artemis
, the necessary dependencies to
connect to an existing Artemis instance are provided, as well as the Spring
infrastructure to integrate with JMS. Adding
org.apache.activemq:artemis-jms-server
to
your application lets you use embedded mode.
|
Artemis configuration is controlled by external configuration properties in
spring.artemis.*
. For example, you might declare the following section in
application.properties
:
spring.artemis.mode=native
spring.artemis.host=192.168.1.210
spring.artemis.port=9876
spring.artemis.user=admin
spring.artemis.password=secret
When embedding the broker, you can choose if you want to enable persistence and list the
destinations that should be made available. These can be specified as a comma-separated
list to create them with the default options, or you can define bean(s) of type
org.apache.activemq.artemis.jms.server.config.JMSQueueConfiguration
or
org.apache.activemq.artemis.jms.server.config.TopicConfiguration
, for advanced queue
and topic configurations, respectively.
By default, a
CachingConnectionFactory
wraps the native
ConnectionFactory
with
sensible settings that you can control by external configuration properties in
spring.jms.*
:
spring.jms.cache.session-cache-size=5
If you’d rather use native pooling, you can do so by adding a dependency to
org.messaginghub:pooled-jms
and configuring the
JmsPoolConnectionFactory
accordingly,
as shown in the following example:
spring.artemis.pool.enabled=true
spring.artemis.pool.max-connections=50
See
ArtemisProperties
for more supported options.
No JNDI lookup is involved, and destinations are resolved against their names, using
either the
name
attribute in the Artemis configuration or the names provided through
configuration.