<?xml version="1.0" encoding="UTF-8"?>

<!-- START SNIPPET: spring -->
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>

  <!--
    || A JCA container for ActiveMQ
    -->
  <bean id="activeMQContainer" class="org.activemq.jca.JCAContainer">

    <!-- the work manager (thread pool) for this container -->
    <property name="workManager">
      <bean id="workManager" class="org.activemq.work.SpringWorkManager">
      </bean>
    </property>

    <!-- the JCA Resource Adapter -->
    <property name="resourceAdapter">
      <bean id="activeMQResourceAdapter" class="org.activemq.ra.ActiveMQResourceAdapter">
        <property name="serverUrl">
          <value>vm://localhost</value>
        </property>
      </bean>
    </property>

  </bean>

  <!--
    || The TransactionManager used for XA transactions
    -->
  <bean id="transactionManager" class="org.springframework.transaction.jta.JotmFactoryBean"/>

  <!--
    || an inbound message connector using a stateless, thread safe MessageListener
    -->
  <bean id="inboundMessageA" factory-method="addConnector" factory-bean="activeMQContainer" singleton="true">

    <!-- subscription details -->
    <property name="activationSpec">
      <bean class="org.activemq.ra.ActiveMQActivationSpec">
        <property name="destination">
          <value>test.spring.inboundMessageA</value>
        </property>
        <property name="destinationType">
          <value>javax.jms.Topic</value>
        </property>
      </bean>
    </property>

    <!-- use XA transactions -->
    <property name="transactionManager"><ref bean="transactionManager"/></property>

    <!-- This example uses a  -->
    <property name="messageListener">
      <ref bean="echoBean"/>
    </property>

  </bean>

  <!--
    || an inbound message connector using a stateful, pooled  MessageListener
    -->
  <bean id="inboundMessageB" factory-method="addConnector" factory-bean="activeMQContainer" singleton="true">

    <!-- subscription details -->
    <property name="activationSpec">
      <bean class="org.activemq.ra.ActiveMQActivationSpec">
        <property name="destination">
          <value>test.spring.inboundMessageB</value>
        </property>
        <property name="destinationType">
          <value>javax.jms.Queue</value>
        </property>
      </bean>
    </property>

    <!-- use XA transactions -->
    <property name="transactionManager"><ref bean="transactionManager"/></property>

    <!-- This example uses a pooled bean -->
    <property name="messageListener">
      <ref bean="pooledEchoBean"/>
    </property>

  </bean>

  <!--
    || Message Driven POJOs
    -->

  <!-- a thread safe non-pooled MessageListener -->
  <bean id="echoBean" class="org.activemq.jca.TestBean">
  </bean>

  <!-- a pooled, non-thread safe MessageListener using ProxyFactoryBean -->
  <bean id="pooledEchoBean" class="org.activemq.jca.TargetSourceMessageListener">
    <property name="targetSource">
      <bean id="pooledEchoBeanTargetSource" class="org.springframework.aop.target.CommonsPoolTargetSource">
        <property name="targetBeanName">
          <value>pooledEchoBeanTarget</value>
        </property>
        <property name="maxSize">
          <value>25</value>
        </property>
      </bean>
    </property>
  </bean>
  <bean id="pooledEchoBeanTarget" class="org.activemq.jca.TestBean" singleton="false">
  </bean>

</beans>

<!-- END SNIPPET: spring -->
