Jboss-fuse-apache-camel

提供:Dev Guides
移動先:案内検索

JBoss Fuse-Apache Camel

この章では、Apache Camelとは何か、エンドポイント間でデータを効果的にルーティングする方法、およびいくつかの例を説明します。

Apache Camelとは何ですか?

Apache Camelは、2007年初頭に開始されたオープンソース統合フレームワークです。

これはEIP(エンタープライズ統合パターン)ベースのアプローチであり、エンタープライズ統合の問題を解決するために使用できる、すぐに使えるパターンの実装をいくつか提供します。 EIPは、エンタープライズ統合でよく文書化され、繰り返し発生する問題に対する実証済みのソリューションに他なりません。

Camelは、エンドポイント間でデータを効率的にルーティングするため、ルーティングおよびメディエーションエンジンとしても知られていますが、データ形式の変換、エンドポイントの接続性などの負荷がかかります。

基本的な例

Apache Camelを使用するための前提条件は次のとおりです-

  • Java
  • メーベン
  • Redhat JBoss Fuse 6.1-GA-379

アプリケーションの基本的なスケルトンを作成する

mvn:archetype generate
–DgroupId = com.tutorialpoint.app
–DartifactId = camel-first-app
–DarchetypeGroupId = org.apache.camel.archetypes
–DarchetypeArtifactId = camel-archetype-spring
–DinteractiveMode = false -X

これにより、次のディレクトリ構造が生成されます。

ディレクトリ構造

これは、生成されるCamelアプリケーションの基本的なスケルトンです。

camel-context.xmlを編集します

*camel-first-app→src→main→resources→META-INF \ spring \ camel-context* .xmlを以下のように編集します
<?xml version = "1.0" encoding = "UTF-8"?>
<!-- Configures the Camel Context-->
<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.xsd
   http://camel.apache.org/schema/spring
   http://camel.apache.org/schema/spring/camel-spring.xsd">

   <camelContext xmlns = "http://camel.apache.org/schema/spring">
      <!-- here is a sample which processes the input file
         (leaving them in place - see the 'noop' flag)
         then performs content based routing on the message using XPath -->

      <route>
         <from uri = "file:///d:/src/data?noop=false"/>
         <choice>
            <when>
               <xpath>/person/city = 'London'</xpath>
               <log message = "UK message"/>
               <to uri = "file:///d:/target/messages/uk"/>
            </when>

            <otherwise>
               <log message = "Other message"/>
               <to uri = "file:///d:/target/messages/others"/>
            </otherwise>

         </choice>

      </route>
   </camelContext>
</beans>

pom.xmlを編集します

<plugins> </plugins>内に次のコードを追加します

<plugin>
   <groupId>org.apache.felix</groupId>
   <artifactId>maven-bundle-plugin</artifactId>
   <version>2.3.4</version>
   <extensions>true</extensions>

   <configuration>
      <instructions>
         <Bundle-SymbolicName>
            ${project.artifactId}
         </Bundle-SymbolicName>
         <Import-Package>*</Import-Package>
      </instructions>
   </configuration>

</plugin>

パッケージの種類を jar→bundle から変更します。

<packaging>bundle</packaging>

次のコマンドを使用してプロジェクトをビルドします-

mvn clean install

Fuseにプロジェクトをインストールする

*Fuse.bat/start.bat* を使用してFuseを起動します。 *start.bat* を使用してFuseを起動する場合は、 *client.bat* を使用してFuseに接続します。 次のスクリーンショットに示すようにUIを取得する必要があります。

ヒューズにプロジェクトをインストール

これはKarafおよびFuseコマンドにアクセスするためのCLIです。

install –s mvn:com.tutorialpoint.app/camel-firt-app/1.0-SNAPSHOT

プロジェクトが実行中かどうかをテストします

これで、アプリケーションがFuseにインストールされます。 camel-first-app 内のデータディレクトリをコピーし、 D:/src/ に配置すると、city = Londonのメッセージを D:/target/merssages/uk にコピーする必要があります。

入力ファイルを D:/src/data に配置します

入力

Message1.xml

<?xml version = "1.0" encoding = "UTF-8"?>
<person user = "james">
   <firstName>James</firstName>
   <lastName>Strachan</lastName>
   <city>London</city>
</person>

Message2.xml

<?xml version = "1.0" encoding = "UTF-8"?>
<person user = "hiram">
   <firstName>Hiram</firstName>
   <lastName>Chirino</lastName>
   <city>Tampa</city>
</person>

出力

D:/target/messages/uk

<?xml version = "1.0" encoding = "UTF-8"?>
<person user = "james">
   <firstName>James</firstName>
   <lastName>Strachan</lastName>
   <city>London</city>
</person>

D:/target/messages/others

<?xml version = "1.0" encoding = "UTF-8"?>
<person user = "hiram">
   <firstName>Hiram</firstName>
   <lastName>Chirino</lastName>
   <city>Tampa</city>
</person>