此内容没有您所选择的语言版本。
Chapter 13. Deploying using a JMS broker
Abstract
Fuse 7.2 does not ship with a default internal broker, but it is designed to interface with four external JMS brokers.
Fuse 7.2 containers contain broker client libraries for the supported external brokers.
See Supported Configurations for more information about the external brokers, client and Camel component combinations that are available for messaging on Fuse 7.2.
13.1. AMQ 7 quickstart
A quickstart is provided to demonstrate the set up and deployment of apps using the AMQ 7 broker.
Setup the quickstart
-
Navigate to
FUSE_HOME/quickstarts/beginner/camel-jms
-
Enter
mvn clean install
to build the quickstart. -
Copy the file
org.ops4j.connectionfactory-amq7.cfg
fromFUSE_HOME/quickstarts/beginner/camel-jms/src/main
directory to theFUSE_HOME/etc
directory in your Fuse installation. Verify its contents for the correct broker URL and credentials. By default, the broker URL is set to tcp://localhost:61616 following AMQ 7’s CORE protocol. Credentials are set to admin/admin. Change these details to suit your external broker. -
Start Fuse by running
./bin/fuse
on Linux orbin\fuse.bat
on Windows. In the Fuse console, enter the following commands:
feature:install pax-jms-pool artemis-jms-client camel-blueprint camel-jms install -s mvn:org.jboss.fuse.quickstarts/camel-jms/${project.version}
Fuse will give you a bundle ID when the bundle is deployed.
-
Enter
log:display
to see the start up log information. Check to make sure the bundle was deployed successfully.
12:13:50.445 INFO [Blueprint Event Dispatcher: 1] Attempting to start Camel Context jms-example-context 12:13:50.446 INFO [Blueprint Event Dispatcher: 1] Apache Camel 2.21.0.fuse-000030 (CamelContext: jms-example-context) is starting 12:13:50.446 INFO [Blueprint Event Dispatcher: 1] JMX is enabled 12:13:50.528 INFO [Blueprint Event Dispatcher: 1] StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html 12:13:50.553 INFO [Blueprint Event Dispatcher: 1] Route: file-to-jms-route started and consuming from: file://work/jms/input 12:13:50.555 INFO [Blueprint Event Dispatcher: 1] Route: jms-cbr-route started and consuming from: jms://queue:incomingOrders?transacted=true 12:13:50.556 INFO [Blueprint Event Dispatcher: 1] Total 2 routes, of which 2 are started
Run the quickstart
-
When the Camel routes run the
FUSE_HOME/quickstarts/beginner/camel-jms/work/jms/input
directory will be created. Copy the files from theFUSE_HOME/quickstarts/beginner/camel-jms/src/main/data
directory to theFUSE_HOME/quickstarts/beginner/camel-jms/work/jms/input
directory. The files copied into the
…/src/main/data
file are order files. Wait for a minute and then check theFUSE_HOME/quickstarts/beginner/camel-jms/work/jms/output
directory. The files will be sorted into separate directories according to their country of destination:-
order1.xml
,order2.xml
andorder4.xml
inFUSE_HOME/quickstarts/beginner/camel-jms/work/jms/output/others/
-
order3.xml
andorder5.xml
inFUSE_HOME/quickstarts/beginner/camel-jms/work/jms/output/us
-
order6.xml
inFUSE_HOME/quickstarts/beginner/camel-jms/work/jms/output/fr
-
-
Use
log:display
to see the log messages:
Receiving order order1.xml Sending order order1.xml to another country Done processing order1.xml
- Camel commands will show details about the context:
Use camel:context-list
to show the context details:
Context Status Total # Failed # Inflight # Uptime ------- ------ ------- -------- ---------- ------ jms-example-context Started 12 0 0 3 minutes
Use camel:route-list
to display the Camel routes in the context:
Context Route Status Total # Failed # Inflight # Uptime ------- ----- ------ ------- -------- ---------- ------ jms-example-context file-to-jms-route Started 6 0 0 3 minutes jms-example-context jms-cbr-route Started 6 0 0 3 minutes
Use camel:route-info
to display the exchange statistics:
karaf@root()> camel:route-info jms-cbr-route jms-example-context Camel Route jms-cbr-route Camel Context: jms-example-context State: Started State: Started Statistics Exchanges Total: 6 Exchanges Completed: 6 Exchanges Failed: 0 Exchanges Inflight: 0 Min Processing Time: 2 ms Max Processing Time: 12 ms Mean Processing Time: 4 ms Total Processing Time: 29 ms Last Processing Time: 4 ms Delta Processing Time: 1 ms Start Statistics Date: 2018-01-30 12:13:50 Reset Statistics Date: 2018-01-30 12:13:50 First Exchange Date: 2018-01-30 12:19:47 Last Exchange Date: 2018-01-30 12:19:47
13.2. Using the Artemis core client
The Artemis core client can be used to connect to an external broker instead of qpid-jms-client
.
Connect using the Artemis core client
-
To enable the Artemis core client, start Fuse. Navigate to the
FUSE_HOME
directory and enter./bin/fuse
on Linux orbin\fuse.bat
on Windows. -
Add the Artemis client as a feature using the following command:
feature:install artemis-core-client
- When you are writing your code you need to connect the Camel component with the connection factory.
Import the connection factory:
import org.apache.qpid.jms.JmsConnectionFactory;
Set up the connection:
ConnectionFactory connectionFactory = new JmsConnectionFactory("amqp://localhost:5672"); try (Connection connection = connectionFactory.createConnection()) {