使用apache camel和jetty进行负载均衡 - 错误

时间:2012-08-14 10:24:08

标签: tcp jetty load-balancing apache-camel

我是骆驼的新手,已经阅读了这本书的骆驼。 我正在开发一个创建负载均衡器的项目。 此负载均衡器将通过端口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>

来自保险丝源的其他一些pluginRepositories。

我的问题是,

是不是,我在这里做的事情? 这条路线会起作用吗? 如果没有其他可能性? 在驼峰上可以做些什么来支持我的项目要求? 非常感谢任何帮助。

1 个答案:

答案 0 :(得分:2)

我通过在POM文件中添加以下依赖项来解决它:

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

希望它有用。