Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.2.4. Integration with JMS
The
camel-jms
component provides messaging support. It integrates with the EAP Messaging (HornetQ) subsystem. Integration with other JMS implementations is possible by using the JBoss generic JMS Resource Adapter.
2.4.1. Configuring EAP JMS Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
With the help of standard EAP XML configuration files, you can configure the EAP messaging subsystem. The following example displays the configuration of a new JMS queue on the messaging subsystem, by adding the XML configuration to the
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
jms-destinations
section.
<jms-queue name="WildFlyCamelQueue"> <entry name="java:/jms/queue/WildFlyCamelQueue"/> </jms-queue>
<jms-queue name="WildFlyCamelQueue">
<entry name="java:/jms/queue/WildFlyCamelQueue"/>
</jms-queue>
However, you can also use a CLI script to add the queue.
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
jms-queue add --queue-address=WildFlyCamelQueue --entries=queue/WildFlyCamelQueue,java:/jms/queue/WildFlyCamelQueue
jms-queue add --queue-address=WildFlyCamelQueue --entries=queue/WildFlyCamelQueue,java:/jms/queue/WildFlyCamelQueue
2.4.2. Configuring Camel Route Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
The following examples of JMS producer and consumer illustrates the use of EAP embedded HornetQ server to publish and consume messages, to and from destinations.
However, it also displays the use of CDI in conjunction with the
camel-cdi
component. You can inject the JMS ConnectionFactory instances into the Camel RouteBuilder via JNDI lookups.
2.4.2.1. JMS Producer Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
You can start the
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
RouteBuilder
by injecting the DefaultJMSConnectionFactory
connection factory from JNDI. However, the connection factory is defined within the messaging subsystem. Also, a timer endpoint runs after every 10 seconds to share an XML payload to the EAPCamelQueue
destination.
When you add a JMS message to the
EAPCamelQueue
destination, a log message appears. Use the EAP Administration console to verify that the messages are placed onto the queue.
2.4.2.2. JMS Consumer Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
To consume JMS messages, inject and set the connection factory from JNDI on the JMSComponent instance. When the JMS endpoint consumes messages from the EAPCamelQueue destination, the content is logged to the console.
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
2.4.2.3. JMS Transactions Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
To enable the Apache Camel JMS routes to participate in JMS transactions, you need to configure some spring classes to enable them to work with the EAP transaction manager and connection factory. The following example illustrates how to use CDI to configure a transactional JMS Camel route.
The
camel-jms
component requires a transaction manager of type org.springframework.transaction.PlatformTransactionManager
. Therefore, you can create a bean extending JtaTransactionManager.
Note
Use the annotation
@Named
to make the bean available to Camel. It enables you to register the bean within the camel bean registry. Also, inject the EAP transaction manager and user transaction instances by using CDI.
Declare the transaction policy that you want to implement. Use the annotation to make the bean available to Camel. Inject the transaction manager, so that you can create a Transactionaltemplate using the desired transaction policy. For example,
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
PROPAGATION_REQUIRED
in this instance.
Also, you can configure the Camel RouteBuilder class and inject the dependencies you need for the Camel JMS component as shown in the given example:
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
2.4.2.4. Remote JMS destinations Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
You can send messages from one EAP instance to HornetQ destinations configured on an other EAP instance, through remote JNDI. To send messages, you need to configure an exported JMS queue. Only JNDI names bound in the
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
java:jboss/export
namespace are appropriate for remote clients.
<jms-queue name="RemoteQueue"> <entry name="java:jboss/exported/jms/queues/RemoteQueue"/> </jms-queue>
<jms-queue name="RemoteQueue">
<entry name="java:jboss/exported/jms/queues/RemoteQueue"/>
</jms-queue>
Note
Configure the queue on the EAP client application server and EAP remote server.