Jencks supports both Inbound JMS messaging as well as outbound messaging.
Outbound messaging (or message outflow to use JCA speak) allows you to pool and reuse JMS sessions and connections when sending messages. In addition JCA takes care of associating inbound and outbound messaging with the same local transaction or XA.
This is very useful if you are inside either a Servlet or EJB type environemnt where you want to send messages from different threads, but don't want to create & close a connection, session, producer for each send.
| Performance Tip JMS is designed for high performance message exchange. It makes heavy use of asynchronous message exchange to boost performance compared to synchronous request/response type systems. However creating and closing connections, sessions, producers is an expensive operation - since each operation will often require a synchronous request/response with the message broker (e.g. for security checks etc). So where possible JMS resources like connections, sessions, producers, consumers should be setup once on startup and reused/pooled. Then a send or receive is a blazingly fast operation. |
Example
The following example shows how to configure the JCA container, a JMS broker, the pool & connection manager, the JMS Resource Adaptor and the JMS ConnectionFactory.
The main bean you'd actually use as an end user is right near the bottom, the jmsConnectionFactory.
<beans> <!-- ###### ActiveMQ Configuration ###### --> <bean id="broker" class="org.apache.activemq.xbean.BrokerFactoryBean"> <property name="config" value="classpath:org/jencks/samples/outbound/broker.xml"/> </bean> <bean id="jmsResourceAdapter" class="org.apache.activemq.ra.ActiveMQResourceAdapter"> <property name="serverUrl" value="vm://localhost"/> </bean> <bean id="jmsQueue" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="queue"/> <property name="jndiEnvironment"> <props> <prop key="java.naming.factory.initial">org.apache.activemq.jndi.ActiveMQInitialContextFactory</prop> <prop key="java.naming.provider.url">tcp://localhost:51616</prop> <prop key="queue.queue">example.MyQueue</prop> </props> </property> </bean> <!-- ###### Transaction manager ###### --> <bean id="transactionManager" class="org.jencks.factory.TransactionManagerFactoryBean"/> <!-- ###### Connection Manager ###### --> <bean id="connectionManager" class="org.jencks.factory.ConnectionManagerFactoryBean"> <property name="transactionManager" ref="transactionManager"/> </bean> <!-- ###### JMS Managed Connection Factory ###### --> <bean id="jmsManagedConnectionFactory" class="org.apache.activemq.ra.ActiveMQManagedConnectionFactory"> <property name="resourceAdapter" ref="jmsResourceAdapter"/> </bean> <!-- ###### JMS Connection Factory ###### --> <bean id="jmsConnectionFactory" class="org.jencks.factory.ConnectionFactoryFactoryBean"> <property name="managedConnectionFactory" ref="jmsManagedConnectionFactory"/> <property name="connectionManager" ref="connectionManager"/> </bean> </beans>
IMPORTANT: The inbound and outbound config MUST match up.
Do NOT use (as shown above):
<bean id="jmsResourceAdapter" class="org.activemq.ra.ActiveMQResourceAdapter"> <property name="serverUrl"> <value>vm://localhost</value> </property> <!--property name="useEmbeddedBroker"> <value>true</value> </property> <property name="brokerXmlConfig"> <value>org/jencks/broker.xml</value> </property--> </bean>
instead use:
<bean id="jmsResourceAdapter" class="org.activemq.ra.ActiveMQResourceAdapter"> <property name="serverUrl" value="tcp://localhost:51616"/> </bean>
if working from the example online. In any case, make sure they match. Hopefully this uh, 'documentation issue', will be fixed/changed at some point in the future (right now the main XML is just a link to a file in the CVS repository so I can't just update it and a new test case would have to be made to fix/explain this more clearly).

Comments (1)
Sep 23, 2005
Wu Xiaofeng says:
Could you give a real sample to show how to use inbound and outbound message tog...Could you give a real sample to show how to use inbound and outbound message together. For example, I want to consume a message, process it and send it out through the same JMS session. How can I config this message driven POJO?