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>

使用来自 fuse 源的其他插件库。

我的问题是,

是不是,我在这里做的事情?这条路线行得通吗?如果不是,其他可能性是什么?骆驼可以做什么来支持我的项目需求?任何帮助将不胜感激。

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 回答