0

私はキャメルの初心者で、キャメルの本を読んだことがあります。ロードバランサーを作成するプロジェクトに取り組んでいます。このロード バランサは、ポート 8080 で SOAP メッセージを介してクライアントからリクエストを取得します。リクエストを取得すると、それらのリクエストをバックエンド サーバーに転送します。これらのバックエンド サーバーは、ポート 8080 でリクエストをリッスンします。リクエストが受信されると、それが処理され、結果がロード バランサーを介してクライアントに返されます。バックエンド サーバーは apache tomcat を使用します。ここで、このシナリオをルーティングするために apache camel を使用することを考えました。fuseIDE をダウンロードし、camel-archtype-java を使用して Maven プロジェクトを作成しました。そして、以下に示すようにキャメルで基本的なルートを書きました:

**MainAPP.java**
package Catload.Loadcat;

import org.apache.camel.main.Main;

public class MainApp {

    /**
     * A main() so we can easily run these routing rules in our IDE
     */
    public static void main(String... args) throws Exception {
        Main main = new Main();
        main.enableHangupSupport();
        main.addRouteBuilder(new MyRouteBuilder());
        main.run(args);
    }

}


**MyRoutebuilder.java**


package Catload.Loadcat;

import org.apache.camel.builder.RouteBuilder;

public class MyRouteBuilder extends RouteBuilder {

    public void configure() {

            from("jetty://http://localhost:8080")
            .loadBalance().roundRobin().to("http://172.168.20.119:8080","http://172.168.20.118:8080");
    }

}

MainApp.java を右クリックし、FuseIDE で Java アプリケーションとして実行を選択すると、エラーが発生します。

Failed to create route route1: Route[[From[jetty://http://localhost:8080]] -> [LoadBalanceT... because of Failed to resolve endpoint: jetty://http://localhost:8080 due to: No component found with scheme: jetty

そして、このプロジェクトをコマンドプロンプトで次のように実行すると

mvn install
mvn exec:java

次のエラー メッセージが表示されます。

[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java (d
efault-cli) on project Loadcat: An exception occured while executing the Java cl
ass. null: InvocationTargetException: Failed to create route route1: Route[[From
[jetty://http://localhost:8080]] -> [LoadBalanceT... because of Failed to resolv
e endpoint: jetty://http://localhost:8080 due to: No component found with scheme
: jetty -> [Help 1]

私のPomファイルは次のとおりです

<dependencies>
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-core</artifactId>
      <version>2.9.0.fuse-7-061</version>
    </dependency>
    <!-- logging -->
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>1.6.1</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
      <version>1.6.1</version>
    </dependency>
    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.16</version>
    </dependency>

    <!-- testing -->
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-test</artifactId>
      <version>2.9.0.fuse-7-061</version>
      <scope>test</scope>
    </dependency>

    <dependency>  
       <groupId>org.mortbay.jetty</groupId>  
       <artifactId>jetty-maven-plugin</artifactId>    
       <version>8.0.1.v20110908</version>  
     </dependency>  
  </dependencies>

  <build>
    <defaultGoal>install</defaultGoal>

    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>

      <plugin>
             <groupId>org.mortbay.jetty</groupId>
             <artifactId>maven-jetty-plugin</artifactId>
             <version>6.1.7</version>
      </plugin> 


      <!-- allows the route to be ran via 'mvn camel:run' -->
      <plugin>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-maven-plugin</artifactId>
        <version>2.9.0.fuse-7-061</version>
      </plugin>

      <!-- Allows the example to be run via 'mvn compile exec:java' -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.2.1</version>
        <configuration>
            <mainClass>Catload.Loadcat.MainApp</mainClass>
            <includePluginDependencies>false</includePluginDependencies>
        </configuration>
      </plugin>

    </plugins>
  </build>

ヒューズソースからの他のプラグインリポジトリがいくつかあります。

私の質問は、

私がここでしていることは正しいですか?このルートは機能しますか?そうでない場合、他の可能性は何ですか?プロジェクトの要件をサポートするために camel で何ができますか? どんな助けでも大歓迎です。

4

1 に答える 1

2

POM ファイルに次の依存関係を追加することで解決しました。

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jetty</artifactId>
<version>2.10.0</version>
</dependency>

お役に立てば幸いです。

于 2012-08-14T13:45:01.677 に答える