이 콘텐츠는 선택한 언어로 제공되지 않습니다.

5.2. Tutorial III: Camel ActiveMQ Component


Overview

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

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

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

Edit the pom.xml file in your Maven project and add the following dependency as a child of the dependencies element:
  <dependencies>
    <dependency>
      <groupId>org.apache.activemq</groupId>
      <artifactId>activemq-core</artifactId>
      <version>5.8.0.redhat-60024</version> <scope>provided</scope> </dependency>
    ...
  </dependencies>
Copy to Clipboard Toggle word wrap

Add package imports

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
Copy to Clipboard Toggle word wrap
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:
<plugins>
  <plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <extensions>true</extensions>
    <configuration>
      <instructions>
        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
	        <Import-Package>org.apache.activemq.xbean,
                            org.apache.activemq.spring,
                            org.apache.activemq.broker,
                            org.apache.activemq.security,
                            org.apache.activemq.jaas,
                            org.apache.activemq.pool,
                            org.apache.activemq.camel.component,
                            org.apache.camel.component.jms,
                            *</Import-Package>
      </instructions>
    </configuration>
  </plugin>
  ...
</plugins>
Copy to Clipboard Toggle word wrap

Configure the Camel ActiveMQ component

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:
<?xml version="1.0" encoding="UTF-8"?>
<beans ... >
  ...
  <!--
    Configure the activemq component:
  -->
  <bean id="jmsConnectionFactory"
        class="org.apache.activemq.ActiveMQSslConnectionFactory">
    <property name="brokerURL" value="ssl://localhost:61001" />
    <property name="userName" value="smx"/>
    <property name="password" value="smx"/>
    <property name="trustStore" value="/conf/client.ts"/>
    <property name="trustStorePassword" value="password"/>
  </bean>

  <bean id="pooledConnectionFactory"
        class="org.apache.activemq.pool.PooledConnectionFactory">
    <property name="maxConnections" value="8" />
    <property name="maximumActive" value="500" />
    <property name="connectionFactory" ref="jmsConnectionFactory" />
  </bean>

  <bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration">
    <property name="connectionFactory" ref="pooledConnectionFactory"/>
    <property name="transacted" value="false"/>
    <property name="concurrentConsumers" value="10"/>
  </bean>

  <bean id="activemqs"
        class="org.apache.activemq.camel.component.ActiveMQComponent">
    <property name="configuration" ref="jmsConfig"/>
  </bean>

</beans>
Copy to Clipboard Toggle word wrap
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

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:
<?xml version="1.0" encoding="UTF-8"?>
<beans ...>
  ...
  <camelContext xmlns="http://camel.apache.org/schema/spring">
    <route>
      <from uri="timer://myTimer?fixedRate=true&amp;period=5000"/>
      <transform><constant>Hello world!</constant></transform>
      <to uri="activemqs:security.test"/>
    </route>
  </camelContext>
  ...
</beans>
Copy to Clipboard Toggle word wrap
You must also add the location of the Apache Camel XML schema to the xsi:schemaLocation attribute, as highlighted in the following example:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core-5.4.0.xsd
       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
    ...
Copy to Clipboard Toggle word wrap

Build the bundle

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
Copy to Clipboard Toggle word wrap

Install the camel-activemq feature

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
Copy to Clipboard Toggle word wrap
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
Copy to Clipboard Toggle word wrap

Deploy the bundle

To deploy and activate the broker bundle, enter the following console command:
JBossFuse:karaf@root> osgi:install -s mvn:org.jbossfuse.example/esb-security
Copy to Clipboard Toggle word wrap

Monitor the queue contents

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
Copy to Clipboard Toggle word wrap
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

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
Copy to Clipboard Toggle word wrap
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat