Class GenericMessageEndpointManager

java.lang.Object
org.springframework.jca.endpoint.GenericMessageEndpointManager
All Implemented Interfaces:
DisposableBean, InitializingBean, Lifecycle, Phased, SmartLifecycle
Direct Known Subclasses:
JmsMessageEndpointManager

public class GenericMessageEndpointManager extends Object implements SmartLifecycle, InitializingBean, DisposableBean
Generic bean that manages JCA 1.7 message endpoints within a Spring application context, activating and deactivating the endpoint as part of the application context's lifecycle.

This class is completely generic in that it may work with any ResourceAdapter, any MessageEndpointFactory, and any ActivationSpec. It can be configured in standard bean style, for example through Spring's XML bean definition format, as follows:

 <bean class="org.springframework.jca.endpoint.GenericMessageEndpointManager">
  <property name="resourceAdapter" ref="resourceAdapter"/>
  <property name="messageEndpointFactory">
    <bean class="org.springframework.jca.endpoint.GenericMessageEndpointFactory">
      <property name="messageListener" ref="messageListener"/>
    </bean>
  </property>
  <property name="activationSpec">
    <bean class="org.apache.activemq.ra.ActiveMQActivationSpec">
      <property name="destination" value="myQueue"/>
      <property name="destinationType" value="jakarta.jms.Queue"/>
    </bean>
  </property>
 </bean>
 

In this example, Spring's own GenericMessageEndpointFactory is used to point to a standard message listener object that happens to be supported by the specified target ResourceAdapter: in this case, a JMS MessageListener object as supported by the ActiveMQ message broker, defined as a Spring bean:

 <bean id="messageListener" class="com.myorg.messaging.myMessageListener">
   <!-- ... -->
 </bean>
 

The target ResourceAdapter may be configured as a local Spring bean as well (the typical case) or obtained from JNDI. For the example above, a local ResourceAdapter bean could be defined as follows (matching the "resourceAdapter" bean reference above):

 <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="..."/>
  </property>
 </bean>
 

For a different target resource, the configuration would simply point to a different ResourceAdapter and a different ActivationSpec object (which are both specific to the resource provider), and possibly a different message listener (for example, a CCI MessageListener for a resource adapter which is based on the JCA Common Client Interface).

The asynchronous execution strategy can be customized through the "workManager" property on the ResourceAdapterFactoryBean as shown above, where <bean class="..."/> should be replaced with configuration for any JCA-compliant WorkManager.

Transactional execution is a responsibility of the concrete message endpoint, as built by the specified MessageEndpointFactory. GenericMessageEndpointFactory supports XA transaction participation through its "transactionManager" property, typically with a Spring JtaTransactionManager or a plain TransactionManager implementation specified there.

 <bean class="org.springframework.jca.endpoint.GenericMessageEndpointManager">
  <property name="resourceAdapter" ref="resourceAdapter"/>
  <property name="messageEndpointFactory">
    <bean class="org.springframework.jca.endpoint.GenericMessageEndpointFactory">
      <property name="messageListener" ref="messageListener"/>
      <property name="transactionManager" ref="transactionManager"/>
    </bean>
  </property>
  <property name="activationSpec">
    <bean class="org.apache.activemq.ra.ActiveMQActivationSpec">
      <property name="destination" value="myQueue"/>
      <property name="destinationType" value="jakarta.jms.Queue"/>
    </bean>
  </property>
 </bean>

 <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>
 

Alternatively, check out your resource provider's ActivationSpec object, which should support local transactions through a provider-specific config flag, for example, ActiveMQActivationSpec's "useRAManagedTransaction" bean property.

 <bean class="org.springframework.jca.endpoint.GenericMessageEndpointManager">
  <property name="resourceAdapter" ref="resourceAdapter"/>
  <property name="messageEndpointFactory">
    <bean class="org.springframework.jca.endpoint.GenericMessageEndpointFactory">
      <property name="messageListener" ref="messageListener"/>
    </bean>
  </property>
  <property name="activationSpec">
    <bean class="org.apache.activemq.ra.ActiveMQActivationSpec">
      <property name="destination" value="myQueue"/>
      <property name="destinationType" value="jakarta.jms.Queue"/>
      <property name="useRAManagedTransaction" value="true"/>
    </bean>
  </property>
 </bean>
 
Since:
2.5
Author:
Juergen Hoeller
See Also: