使用阿帕奇骆驼和码头进行负载平衡 - 错误


我是骆驼

的新手,读过骆驼在行动。我正在开发一个创建负载均衡器的项目。此负载均衡器将通过端口 8080 上的 SOAP 消息从客户端获取请求。一旦它收到请求,它会将这些请求转发到后端服务器。这些后端服务器将侦听端口 8080 以获取请求。收到请求后,将提供该请求,并通过负载均衡器将结果返回给客户端。后端服务器使用 apache tomcat。现在我想到使用阿帕奇骆驼来路由这个场景。我下载了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>

很少有其他插件来自保险丝源的存储库。

我的问题是,

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

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

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

希望对您有所帮助。

最新更新