2023-04-19 23:26:16 +08:00
|
|
|
[[jms-jca-message-endpoint-manager]]
|
|
|
|
= Support for JCA Message Endpoints
|
|
|
|
|
|
|
|
Beginning with version 2.5, Spring also provides support for a JCA-based
|
|
|
|
`MessageListener` container. The `JmsMessageEndpointManager` tries to
|
|
|
|
automatically determine the `ActivationSpec` class name from the provider's
|
|
|
|
`ResourceAdapter` class name. Therefore, it is typically possible to provide
|
|
|
|
Spring's generic `JmsActivationSpecConfig`, as the following example shows:
|
|
|
|
|
|
|
|
[source,xml,indent=0,subs="verbatim,quotes"]
|
|
|
|
----
|
|
|
|
<bean class="org.springframework.jms.listener.endpoint.JmsMessageEndpointManager">
|
|
|
|
<property name="resourceAdapter" ref="resourceAdapter"/>
|
|
|
|
<property name="activationSpecConfig">
|
|
|
|
<bean class="org.springframework.jms.listener.endpoint.JmsActivationSpecConfig">
|
|
|
|
<property name="destinationName" value="myQueue"/>
|
|
|
|
</bean>
|
|
|
|
</property>
|
|
|
|
<property name="messageListener" ref="myMessageListener"/>
|
|
|
|
</bean>
|
|
|
|
----
|
|
|
|
|
|
|
|
Alternatively, you can set up a `JmsMessageEndpointManager` with a given
|
|
|
|
`ActivationSpec` object. The `ActivationSpec` object may also come from a JNDI lookup
|
|
|
|
(using `<jee:jndi-lookup>`). The following example shows how to do so:
|
|
|
|
|
|
|
|
[source,xml,indent=0,subs="verbatim,quotes"]
|
|
|
|
----
|
|
|
|
<bean class="org.springframework.jms.listener.endpoint.JmsMessageEndpointManager">
|
|
|
|
<property name="resourceAdapter" ref="resourceAdapter"/>
|
|
|
|
<property name="activationSpec">
|
|
|
|
<bean class="org.apache.activemq.ra.ActiveMQActivationSpec">
|
|
|
|
<property name="destination" value="myQueue"/>
|
|
|
|
<property name="destinationType" value="jakarta.jms.Queue"/>
|
|
|
|
</bean>
|
|
|
|
</property>
|
|
|
|
<property name="messageListener" ref="myMessageListener"/>
|
|
|
|
</bean>
|
|
|
|
----
|
|
|
|
|
|
|
|
Using Spring's `ResourceAdapterFactoryBean`, you can configure the target `ResourceAdapter`
|
|
|
|
locally, as the following example shows:
|
|
|
|
|
|
|
|
[source,xml,indent=0,subs="verbatim,quotes"]
|
|
|
|
----
|
|
|
|
<bean id="resourceAdapter" class="org.springframework.jca.support.ResourceAdapterFactoryBean">
|
|
|
|
<property name="resourceAdapter">
|
|
|
|
<bean class="org.apache.activemq.ra.ActiveMQResourceAdapter">
|
|
|
|
<property name="serverUrl" value="tcp://localhost:61616"/>
|
|
|
|
</bean>
|
|
|
|
</property>
|
|
|
|
<property name="workManager">
|
|
|
|
<bean class="org.springframework.jca.work.SimpleTaskWorkManager"/>
|
|
|
|
</property>
|
|
|
|
</bean>
|
|
|
|
----
|
|
|
|
|
|
|
|
The specified `WorkManager` can also point to an environment-specific thread pool --
|
2023-08-12 20:50:45 +08:00
|
|
|
typically through a `SimpleTaskWorkManager` instance's `asyncTaskExecutor` property.
|
|
|
|
Consider defining a shared thread pool for all your `ResourceAdapter` instances
|
|
|
|
if you happen to use multiple adapters.
|
2023-04-19 23:26:16 +08:00
|
|
|
|
2023-08-12 20:50:45 +08:00
|
|
|
In some environments, you can instead obtain the entire `ResourceAdapter` object from JNDI
|
|
|
|
(by using `<jee:jndi-lookup>`). The Spring-based message listeners can then interact with
|
|
|
|
the server-hosted `ResourceAdapter`, which also use the server's built-in `WorkManager`.
|
2023-04-19 23:26:16 +08:00
|
|
|
|
|
|
|
See the javadoc for {api-spring-framework}/jms/listener/endpoint/JmsMessageEndpointManager.html[`JmsMessageEndpointManager`],
|
|
|
|
{api-spring-framework}/jms/listener/endpoint/JmsActivationSpecConfig.html[`JmsActivationSpecConfig`],
|
|
|
|
and {api-spring-framework}/jca/support/ResourceAdapterFactoryBean.html[`ResourceAdapterFactoryBean`]
|
|
|
|
for more details.
|
|
|
|
|
|
|
|
Spring also provides a generic JCA message endpoint manager that is not tied to JMS:
|
|
|
|
`org.springframework.jca.endpoint.GenericMessageEndpointManager`. This component allows
|
|
|
|
for using any message listener type (such as a JMS `MessageListener`) and any
|
|
|
|
provider-specific `ActivationSpec` object. See your JCA provider's documentation to
|
|
|
|
find out about the actual capabilities of your connector, and see the
|
|
|
|
{api-spring-framework}/jca/endpoint/GenericMessageEndpointManager.html[`GenericMessageEndpointManager`]
|
|
|
|
javadoc for the Spring-specific configuration details.
|
|
|
|
|
|
|
|
NOTE: JCA-based message endpoint management is very analogous to EJB 2.1 Message-Driven Beans.
|
|
|
|
It uses the same underlying resource provider contract. As with EJB 2.1 MDBs, you can use any
|
|
|
|
message listener interface supported by your JCA provider in the Spring context as well.
|
|
|
|
Spring nevertheless provides explicit "`convenience`" support for JMS, because JMS is the
|
|
|
|
most common endpoint API used with the JCA endpoint management contract.
|
|
|
|
|
|
|
|
|
|
|
|
|