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.Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
5.2. Tutorial III: Camel ActiveMQ Component
Overview Link kopierenLink in die Zwischenablage kopiert!
Link kopierenLink in die Zwischenablage kopiert!
This tutorial explains how to define a route featuring an Apache ActiveMQ endpoint, where the route is defined using Spring XML and then deployed into the OSGi container as a bundle. The implementation of the route is simple: it generates a stream of messages using a timer and the messages are then sent to a JMS queue in an Apache ActiveMQ broker.
The key feature of this example is that the Apache ActiveMQ endpoint at the end of the route must be configured to open a secure connection to the broker. In order to define a secure endpoint, the Apache ActiveMQ component is customized to enable both SSL security and JAAS security in the underlying JMS connection factory.
Prerequisites Link kopierenLink in die Zwischenablage kopiert!
Link kopierenLink in die Zwischenablage kopiert!
This tutorial part builds on Section 4.1, “Tutorial I: SSL/TLS Security” and Section 4.3, “Tutorial II: JAAS Authentication”. All of the prerequisites from the section called “Prerequisites” apply here and you must complete the previous tutorial parts before proceeding.
Tutorial steps Link kopierenLink in die Zwischenablage kopiert!
Link kopierenLink in die Zwischenablage kopiert!
To define a route, which is deployed in the OSGi container and can communicate with a secure Apache ActiveMQ endpoint, perform the following steps:
Add Maven dependency Link kopierenLink in die Zwischenablage kopiert!
Link kopierenLink in die Zwischenablage kopiert!
Edit the
pom.xml file in your Maven project and add the following dependency as a child of the dependencies element:
Add package imports Link kopierenLink in die Zwischenablage kopiert!
Link kopierenLink in die Zwischenablage kopiert!
In order to build the Apache Camel route in Maven, you need to add the following package imports to the configuration of the
maven-bundle-plugin plug-in:
org.apache.activemq.pool org.apache.activemq.camel.component, org.apache.camel.component.jms
org.apache.activemq.pool
org.apache.activemq.camel.component,
org.apache.camel.component.jms
These imports are needed, because the Maven bundle plug-in is not able to figure out all of the imports required by beans created in the Spring configuration file.
Edit the
pom.xml file in your Maven project and add the preceding package imports, so that the maven-bundle-plugin configuration looks like the following:
Configure the Camel ActiveMQ component Link kopierenLink in die Zwischenablage kopiert!
Link kopierenLink in die Zwischenablage kopiert!
Edit the
broker-spring.xml file in the src/main/resources/META-INF/spring directory of your Maven project and add the following bean definitions, which configure the Camel ActiveMQ component:
This configuration defines the secure
activemqs component, which you can now use to define endpoints in your Apache Camel routes. The activemqs bean references jmsConfig, which configures the the component. The jmsConfig bean in turn references a chain of JMS connection factories: the pooled connection factory wrapper, pooledConnectionFactory, which is important for performance; and the secure connection factory, jmsConnectionFactory, which is capable of creating secure connections to the broker.
Configure the Camel route Link kopierenLink in die Zwischenablage kopiert!
Link kopierenLink in die Zwischenablage kopiert!
Configure a Apache Camel route that generates messages using a timer endpoint and then sends the generated messages to the
security.test queue on the secure broker. For this route, you need to use the secure activemqs component to define the endpoint that connects to the broker.
Edit the
broker-spring.xml file in the src/main/resources/META-INF/spring directory of your Maven project and add the following camelContext element, which contains the route definition:
You must also add the location of the Apache Camel XML schema to the
xsi:schemaLocation attribute, as highlighted in the following example:
Build the bundle Link kopierenLink in die Zwischenablage kopiert!
Link kopierenLink in die Zwischenablage kopiert!
Use Maven to build the bundle. Open a command prompt, switch the current directory to
ProjectDir/esb-security, and then enter the following command:
mvn clean install
mvn clean install
Install the camel-activemq feature Link kopierenLink in die Zwischenablage kopiert!
Link kopierenLink in die Zwischenablage kopiert!
If you have not already done so, start up the Apache ServiceMix console (and container instance) by entering the following command in a new command prompt:
servicemix
servicemix
The
camel-activemq feature, which defines the bundles required for the Camel ActiveMQ component, is not installed by default. To install the camel-activemq feature, enter the following console command:
JBossFuse:karaf@root> features:install camel-activemq
JBossFuse:karaf@root> features:install camel-activemq
Deploy the bundle Link kopierenLink in die Zwischenablage kopiert!
Link kopierenLink in die Zwischenablage kopiert!
To deploy and activate the broker bundle, enter the following console command:
JBossFuse:karaf@root> osgi:install -s mvn:org.jbossfuse.example/esb-security
JBossFuse:karaf@root> osgi:install -s mvn:org.jbossfuse.example/esb-security
Monitor the queue contents Link kopierenLink in die Zwischenablage kopiert!
Link kopierenLink in die Zwischenablage kopiert!
You can monitor the contents of the
security.test queue using a JMX management tool, such as Java's jconsole. Open a command prompt and enter the following command:
jconsole
jconsole
A JConsole: Connect to Agent dialog opens. From the Local tab, select the
org.apache.karaf.main.Main entry and click Connect. The main JConsole window appears. Select the MBeans tab and then drill down to org.apache.activemq|Queue|security.test, as shown in the screenshot below. From the EnqueueCount bean attribute, you can see how many messages have been sent to the queue. By clicking Refresh to update the bean attributes, you can see that messages are arriving at the rate of one every five seconds.
Uninstall the broker bundle Link kopierenLink in die Zwischenablage kopiert!
Link kopierenLink in die Zwischenablage kopiert!
To uninstall the broker bundle, you need to know its bundle ID, BundleID, in which case you can uninstall it by entering the following console command:
JBossFuse:karaf@root> osgi:uninstall BundleID
JBossFuse:karaf@root> osgi:uninstall BundleID