このコンテンツは選択した言語では利用できません。
Chapter 2. Getting started with transactions on Karaf (OSGi)
This section describes a Camel application that uses transactions to access an Artemis JMS broker. The information is organized as follows:
2.1. Prerequisites リンクのコピーリンクがクリップボードにコピーされました!
Implementation of this Camel application has the following prerequisites:
An external AMQ 7 JMS message broker must be running.
The following sample code runs a standalone (non-Docker) version of
amq-broker-7.1.0-bin.zip
. Execution creates and runs anamq7
instance:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Client libraries are required. Artemis libraries are available in Maven Central or a Red Hat repository. For example, you can use:
-
mvn:org.apache.activemq/artemis-core-client/2.4.0.amq-710008-redhat-1
-
mvn:org.apache.activemq/artemis-jms-client/2.4.0.amq-710008-redhat-1
Alternatively, Artemis/AMQ 7 client libraries can be installed as Karaf features, for example:
-
karaf@root()> feature:install artemis-jms-client artemis-core-client
-
Some supporting features that provide Karaf shell commands or dedicated Artemis support are required:
karaf@root()> feature:install jms pax-jms-artemis pax-jms-config
karaf@root()> feature:install jms pax-jms-artemis pax-jms-config
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Required Camel features are:
karaf@root()> feature:install camel-jms camel-blueprint
karaf@root()> feature:install camel-jms camel-blueprint
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.2. Building the camel-jms project リンクのコピーリンクがクリップボードにコピーされました!
The Fuse distribution contains the quickstarts/camel/camel-jms
example, which you can build and install as an OSGi bundle. This bundle contains a Blueprint XML definition of a Camel route that sends messages to an AMQ 7 JMS queue.
In the following example, $FUSE_HOME
is the location of the unzipped Fuse distribution. To build this project:
Invoke Maven to build the project:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a JMS connection factory configuration so that the
javax.jms.ConnectionFactory
service is published in the OSGi runtime. To do this, copy$FUSE_HOME/quickstarts/camel/camel-jms/src/main/resources/etc/org.ops4j.connectionfactory-amq7.cfg
into the$FUSE_HOME/etc
directory. This configuration will be processed to create a working connection factory. For example:cp camel/camel-jms/src/main/resources/etc/org.ops4j.connectionfactory-amq7.cfg ../etc/
$ cp camel/camel-jms/src/main/resources/etc/org.ops4j.connectionfactory-amq7.cfg ../etc/
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Verify the published connection factory:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Install the bundle:
karaf@root()> install -s mvn:org.jboss.fuse.quickstarts/camel-jms/7.0.0.redhat-SNAPSHOT Bundle ID: 256
karaf@root()> install -s mvn:org.jboss.fuse.quickstarts/camel-jms/7.0.0.redhat-SNAPSHOT Bundle ID: 256
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Confirm that it is working:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
As soon as the Camel routes have started, you can see a directory,
work/jms/input
, in your Fuse installation. Copy the files you find in this quickstart’ssrc/main/data
directory to the newly createdwork/jms/input
directory. Wait a few moments and you will find the same files organized by country under the
work/jms/output
directory:-
order1.xml
,order2.xml
andorder4.xml
inwork/jms/output/others
-
order3.xml
andorder5.xml
inwork/jms/output/us
-
order6.xml
inwork/jms/output/fr
-
See the logs to check out the business logging:
2018-05-02 17:20:47,952 | INFO | ile://work/jms/input | file-to-jms-route | 58 - org.apache.camel.camel-core - 2.21.0.fuse-000077 | Receiving order order1.xml 2018-05-02 17:20:48,052 | INFO | umer[incomingOrders] | jms-cbr-route | 58 - org.apache.camel.camel-core - 2.21.0.fuse-000077 | Sending order order1.xml to another country 2018-05-02 17:20:48,053 | INFO | umer[incomingOrders] | jms-cbr-route | 58 - org.apache.camel.camel-core - 2.21.0.fuse-000077 | Done processing order1.xml
2018-05-02 17:20:47,952 | INFO | ile://work/jms/input | file-to-jms-route | 58 - org.apache.camel.camel-core - 2.21.0.fuse-000077 | Receiving order order1.xml 2018-05-02 17:20:48,052 | INFO | umer[incomingOrders] | jms-cbr-route | 58 - org.apache.camel.camel-core - 2.21.0.fuse-000077 | Sending order order1.xml to another country 2018-05-02 17:20:48,053 | INFO | umer[incomingOrders] | jms-cbr-route | 58 - org.apache.camel.camel-core - 2.21.0.fuse-000077 | Done processing order1.xml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow See that the queue was dynamically created:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Check Camel route statistics:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.3. Explanation of the camel-jms project リンクのコピーリンクがクリップボードにコピーされました!
Camel routes are using the following endpoint URIs:
The jms
component is configured by using this snippet:
While the transactionManager
reference is:
<reference id="transactionManager" interface="org.springframework.transaction.PlatformTransactionManager" />
<reference id="transactionManager" interface="org.springframework.transaction.PlatformTransactionManager" />
As you can see, both the JMS connection factory and the Spring interface of PlatformTransactionManager
are only references. There is no need to define them in Blueprint XML. These services are exposed by Fuse itself.
You have already seen that javax.jms.ConnectionFactory
was created by using etc/org.ops4j.connectionfactory-amq7.cfg
.
The transaction manager is:
Check for other interfaces under which the actual transaction manager is registered:
The transaction manager is available from these interfaces:
-
javax.transaction.TransactionManager
-
javax.transaction.TransactionSynchronizationRegistry
-
javax.transaction.UserTransaction
-
org.jboss.narayana.osgi.jta.ObjStoreBrowserService
-
org.ops4j.pax.transx.tm.TransactionManager
-
org.springframework.transaction.PlatformTransactionManager
You can use any of them in any context that you need. For example camel-jms
requires that the org.apache.camel.component.jms.JmsConfiguration.transactionManager
field be initialized. This is why the example uses:
<reference id="transactionManager" interface="org.springframework.transaction.PlatformTransactionManager" />
<reference id="transactionManager" interface="org.springframework.transaction.PlatformTransactionManager" />
instead of, for example:
<reference id="transactionManager" interface="javax.transaction.TransactionManager" />
<reference id="transactionManager" interface="javax.transaction.TransactionManager" />