0
votes

I am a newbie in camel and have read the book camel in action. I am working on a project to create a load balancer. This load balancer would get the request from a client via SOAP message on the port 8080. Once it gets the request it would forward those request to backend servers. These backend servers would listen to port 8080 for the request. Once the request is recieved it is then served and the result is given back to client via the load balancer. The backend servers use apache tomcat. Now I thought of using apache camel to route this scenario. I dowloaded fuseIDE and created a maven project using camel-archtype-java. And Wrote a basic route in camel as shown below:

**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");
    }

}

Now when i right click the MainApp.java and select run as java application in FuseIDE i get the error

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

And when I run this project in command prompt as

mvn install
mvn exec:java

I get the following error message:

[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]

My Pom file is as follows

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

With few other pluginRepositories from fuse source.

My question is,

Is it right, the things that i am doing here? Will this route work? If not what are the other possibilities? What can be done in camel to support my project requirements? Any help would be very much appreciated.

1

1 Answers

2
votes

I resolved it, by adding the following dependency in the POM file:

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

Hope it is helpful.