Author: davsclaus
Date: Wed Dec 28 12:38:53 2011
New Revision: 1225170
URL: http://svn.apache.org/viewvc?rev=1225170&view=rev
Log:
Polished example
Modified:
camel/trunk/examples/camel-example-loadbalancing/README.txt
camel/trunk/examples/camel-example-loadbalancing/pom.xml
camel/trunk/examples/camel-example-loadbalancing/src/main/java/org/apache/camel/example/model/Report.java
camel/trunk/examples/camel-example-loadbalancing/src/main/java/org/apache/camel/example/service/Generator.java
camel/trunk/examples/camel-example-loadbalancing/src/main/java/org/apache/camel/example/service/Reporting.java
camel/trunk/examples/camel-example-loadbalancing/src/main/resources/META-INF/spring/camel-context-loadbalancer.xml
camel/trunk/examples/camel-example-loadbalancing/src/main/resources/META-INF/spring/camel-context-mina1.xml
camel/trunk/examples/camel-example-loadbalancing/src/main/resources/META-INF/spring/camel-context-mina2.xml
Modified: camel/trunk/examples/camel-example-loadbalancing/README.txt
URL:
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-loadbalancing/README.txt?rev=1225170&r1=1225169&r2=1225170&view=diff
==============================================================================
--- camel/trunk/examples/camel-example-loadbalancing/README.txt (original)
+++ camel/trunk/examples/camel-example-loadbalancing/README.txt Wed Dec 28
12:38:53 2011
@@ -1,108 +1,21 @@
Load balancing with MINA Example
================================
-This example show how you can easily use the camel-mina component to design a
solution allowing to distribute message
-workload on several servers. Those servers are simple TCP/IP servers created
by the Apache MINA framework and running in
-separate Java Virtual Machine. The loadbalancer pattern of Camel which is used
top of them allows to send in a Round Robin model
-mode the messages created from a camel Bean component respectively to each
server running on localhost:9999 and localhost:9998.
-MINA has been configured to send over the wire objects serialized and this is
what is showed also in this example.
-The advantage of this approach is that you don't need to use CORBA or Java RMI
for the communication between the different JVMs.
-The example has been configured to use InOut EIP pattern.
-
-The demo starts when every one minute, a Report object is created from the
camel loadbalancer server. This object is send by the
-camel loadbalancer to a MINA server and object is serialized. One of the two
MINA servers (localhost:9999 and localhost:9998) receives
-the object and enrich it by setting the field reply of the Report object. The
reply is send back by the MINA server to the camel loadbalancer
-who will display in its log the content of the Report object.
+This example show how you can easily use the camel-mina component to design a
solution
+allowing to distribute message workload on several servers.
+These servers are simple TCP/IP servers created by the Apache MINA framework
and running in
+separate JVMs. The load balancer pattern of Camel which is used top of them
allows to
+send in a Round Robin model mode the messages created from a camel Bean
component
+respectively to each server running on localhost:9991 and localhost:9992.
+
+The demo starts when every 5th seconds, a Report object is created from the
camel load balancer server.
+This object is send by the camel load balancer to a MINA server and object is
serialized.
+One of the two MINA servers (localhost:9991 and localhost:9992) receives the
object and enrich the message
+by setting the field reply of the Report object. The reply is send back by the
MINA server to the client,
+which then logs the reply on the console.
-For the latest & greatest documentation on how to use this example please see
- http://camel.apache.org/loadbalancing-mina-example.html
-
-
-1. Description of the routes
-============================
-
-1) Loadbalancer
-
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:camel="http://camel.apache.org/schema/spring"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
- http://camel.apache.org/schema/spring
- http://camel.apache.org/schema/spring/camel-spring.xsd ">
-
-<bean id="service" class="org.apache.camel.example.service.Generator"/>
-
-<camelContext xmlns="http://camel.apache.org/schema/spring" trace="false">
-
- <route id="sendMessage">
- <from
uri="timer://org.apache.camel.example.loadbalancer?fixedRate=true&period=60000"/>
- <bean ref="service" method="createReport"/>
- <to uri="direct:loadbalance"/>
- </route>
-
- <route id="loadbalancer">
- <from uri="direct:loadbalance"/>
- <loadBalance>
- <roundRobin/>
- <to
uri="mina:tcp://localhost:9999?sync=true&allowDefaultCodec=true"/>
- <to
uri="mina:tcp://localhost:9998?sync=true&allowDefaultCodec=true"/>
- </loadBalance>
- <to uri="log:org.apache.camel.example?level=INFO"/>
- </route>
-</camelContext>
-
-</beans>
-
-2) MINA 1
-
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:camel="http://camel.apache.org/schema/spring"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
- http://camel.apache.org/schema/spring
- http://camel.apache.org/schema/spring/camel-spring.xsd ">
-
-<bean id="service" class="org.apache.camel.example.service.Reporting"/>
-
-<camelContext xmlns="http://camel.apache.org/schema/spring" trace="false">
- <route id="mina1">
- <from uri="mina:tcp://localhost:9999"/>
- <setHeader
headerName="minaServer"><constant>localhost:9999</constant></setHeader>
- <bean ref="service" method="updateReport"/>
- </route>
-</camelContext>
-
-</beans>
-
-2) MINA 2
-
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:camel="http://camel.apache.org/schema/spring"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
- http://camel.apache.org/schema/spring
- http://camel.apache.org/schema/spring/camel-spring.xsd ">
-
-<bean id="service" class="org.apache.camel.example.service.Reporting"/>
-
-<camelContext xmlns="http://camel.apache.org/schema/spring" trace="false">
- <route id="mina1">
- <from uri="mina:tcp://localhost:9998"/>
- <setHeader
headerName="minaServer"><constant>localhost:9999</constant></setHeader>
- <bean ref="service" method="updateReport"/>
- </route>
-</camelContext>
-
-</beans>
-
-2. Test the example
+Running the example
===================
To compile and install the project in your maven repo, execute the following
command on the
@@ -121,40 +34,6 @@ mvn exec:java -Pmina2
>loadbalancing
mvn exec:java -Ploadbalancer
-and check the result in the log of loadbalancer
-
-[pache.camel.spring.Main.main()] MainSupport INFO Apache
Camel 2.2.0 starting
-[pache.camel.spring.Main.main()] CamelNamespaceHandler INFO
camel-osgi.jar/camel-spring-osgi.jar not detected in classpath
-[pache.camel.spring.Main.main()] DefaultCamelContext INFO Apache
Camel 2.2.0 (CamelContext:camelContext) is starting
-[pache.camel.spring.Main.main()] DefaultCamelContext INFO JMX
enabled. Using DefaultManagedLifecycleStrategy.
-[pache.camel.spring.Main.main()] DefaultCamelContext INFO Started
2 routes
-[pache.camel.spring.Main.main()] DefaultCamelContext INFO Apache
Camel 2.2.0 (CamelContext:camelContext) started
-[che.camel.example.loadbalancer] example INFO
Exchange[BodyType:org.apache.camel.example.model.Report, Body:>> ***************
-********************************
->> Report id : 1
->> Report title : Report Title : 1
->> Report content : This is a dummy report
->> Report reply : Report updated from MINA server running on : localhost:9999
->> ***********************************************
-]
-[che.camel.example.loadbalancer] example INFO
Exchange[BodyType:org.apache.camel.example.model.Report, Body:>> ***************
-********************************
->> Report id : 2
->> Report title : Report Title : 2
->> Report content : This is a dummy report
->> Report reply : Report updated from MINA server running on : localhost:9998
->> ***********************************************
-]
-[che.camel.example.loadbalancer] example INFO
Exchange[BodyType:org.apache.camel.example.model.Report, Body:>> ***************
-********************************
->> Report id : 3
->> Report title : Report Title : 3
->> Report content : This is a dummy report
->> Report reply : Report updated from MINA server running on : localhost:9999
->> ***********************************************
-]
-...
-
This example is documented at
http://camel.apache.org/loadbalancing-mina-example.html
Modified: camel/trunk/examples/camel-example-loadbalancing/pom.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-loadbalancing/pom.xml?rev=1225170&r1=1225169&r2=1225170&view=diff
==============================================================================
--- camel/trunk/examples/camel-example-loadbalancing/pom.xml (original)
+++ camel/trunk/examples/camel-example-loadbalancing/pom.xml Wed Dec 28
12:38:53 2011
@@ -29,8 +29,8 @@
<artifactId>camel-example-loadbalancing</artifactId>
<packaging>jar</packaging>
- <name>Camel :: Example :: Loadbalancer camel-mina</name>
- <description>An example that show loadbalancing messaging with mina
servers (TCP/IP)</description>
+ <name>Camel :: Example :: Load Balancing</name>
+ <description>An example that demonstrate load balancing messaging with
mina servers (TCP/IP)</description>
<dependencies>
@@ -48,10 +48,10 @@
</dependency>
<!-- logging -->
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ </dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
@@ -88,13 +88,7 @@
<build>
<plugins>
- <!-- allows the route to be ran via 'mvn camel:run' -->
- <plugin>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-maven-plugin</artifactId>
- <version>${project.version}</version>
- </plugin>
-
+
<!-- Allows the example to be run via 'mvn compile exec:java' -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
Modified:
camel/trunk/examples/camel-example-loadbalancing/src/main/java/org/apache/camel/example/model/Report.java
URL:
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-loadbalancing/src/main/java/org/apache/camel/example/model/Report.java?rev=1225170&r1=1225169&r2=1225170&view=diff
==============================================================================
---
camel/trunk/examples/camel-example-loadbalancing/src/main/java/org/apache/camel/example/model/Report.java
(original)
+++
camel/trunk/examples/camel-example-loadbalancing/src/main/java/org/apache/camel/example/model/Report.java
Wed Dec 28 12:38:53 2011
@@ -27,70 +27,46 @@ public class Report implements Serializa
private String content;
private String reply;
- /**
- * @return the id
- */
public Integer getId() {
return id;
}
- /**
- * @param id the id to set
- */
public void setId(Integer id) {
this.id = id;
}
- /**
- * @return the title
- */
public String getTitle() {
return title;
}
- /**
- * @param title the title to set
- */
public void setTitle(String title) {
this.title = title;
}
- /**
- * @return the content
- */
public String getContent() {
return content;
}
- /**
- * @param content the content to set
- */
public void setContent(String content) {
this.content = content;
}
- /**
- * @return the reply
- */
public String getReply() {
return reply;
}
- /**
- * @param reply the reply to set
- */
public void setReply(String reply) {
this.reply = reply;
}
public String toString() {
StringBuilder result = new StringBuilder();
- result.append(">> ***********************************************" +
"\n");
- result.append(">> Report id : " + this.id + "\n");
- result.append(">> Report title : " + this.title + "\n");
- result.append(">> Report content : " + this.content + "\n");
- result.append(">> Report reply : " + this.reply + "\n");
- result.append(">> ***********************************************" +
"\n");
+ result.append("\n>>
***********************************************\n");
+ result.append(">> Report id: " + this.id + "\n");
+ result.append(">> Report title: " + this.title + "\n");
+ result.append(">> Report content: " + this.content + "\n");
+ result.append(">> Report reply: " + this.reply + "\n");
+ result.append(">> ***********************************************\n");
return result.toString();
}
}
Modified:
camel/trunk/examples/camel-example-loadbalancing/src/main/java/org/apache/camel/example/service/Generator.java
URL:
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-loadbalancing/src/main/java/org/apache/camel/example/service/Generator.java?rev=1225170&r1=1225169&r2=1225170&view=diff
==============================================================================
---
camel/trunk/examples/camel-example-loadbalancing/src/main/java/org/apache/camel/example/service/Generator.java
(original)
+++
camel/trunk/examples/camel-example-loadbalancing/src/main/java/org/apache/camel/example/service/Generator.java
Wed Dec 28 12:38:53 2011
@@ -23,13 +23,12 @@ public class Generator {
private static int count;
public Report createReport() throws Exception {
-
int counter = ++count;
// Create a Report object
Report report = new Report();
report.setId(counter);
- report.setTitle("Report Title : " + counter);
+ report.setTitle("Report Title: " + counter);
report.setContent("This is a dummy report");
// Add the report to the Body
Modified:
camel/trunk/examples/camel-example-loadbalancing/src/main/java/org/apache/camel/example/service/Reporting.java
URL:
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-loadbalancing/src/main/java/org/apache/camel/example/service/Reporting.java?rev=1225170&r1=1225169&r2=1225170&view=diff
==============================================================================
---
camel/trunk/examples/camel-example-loadbalancing/src/main/java/org/apache/camel/example/service/Reporting.java
(original)
+++
camel/trunk/examples/camel-example-loadbalancing/src/main/java/org/apache/camel/example/service/Reporting.java
Wed Dec 28 12:38:53 2011
@@ -17,19 +17,13 @@
package org.apache.camel.example.service;
import org.apache.camel.Body;
-import org.apache.camel.Exchange;
import org.apache.camel.Header;
-import org.apache.camel.Processor;
import org.apache.camel.example.model.Report;
-public class Reporting implements Processor {
+public class Reporting {
-
- public void process(Exchange exchange) throws Exception {
- }
-
- public Report updateReport(@Body Report report, @Header("minaServer")
String name) throws Exception {
- report.setReply("Report updated from MINA server running on : " +
name);
+ public Report updateReport(@Body Report report, @Header("minaServer")
String name) {
+ report.setReply("Report updated from MINA server running on: " + name);
// send the report updated
return report;
Modified:
camel/trunk/examples/camel-example-loadbalancing/src/main/resources/META-INF/spring/camel-context-loadbalancer.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-loadbalancing/src/main/resources/META-INF/spring/camel-context-loadbalancer.xml?rev=1225170&r1=1225169&r2=1225170&view=diff
==============================================================================
---
camel/trunk/examples/camel-example-loadbalancing/src/main/resources/META-INF/spring/camel-context-loadbalancer.xml
(original)
+++
camel/trunk/examples/camel-example-loadbalancing/src/main/resources/META-INF/spring/camel-context-loadbalancer.xml
Wed Dec 28 12:38:53 2011
@@ -16,8 +16,7 @@
limitations under the License.
-->
-<!-- Configures the Camel Context-->
-
+<!-- START SNIPPET: e1 -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/spring"
@@ -27,10 +26,10 @@
<bean id="service" class="org.apache.camel.example.service.Generator"/>
- <camelContext xmlns="http://camel.apache.org/schema/spring" trace="false">
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
<route id="sendMessage">
- <from
uri="timer://org.apache.camel.example.loadbalancer?fixedRate=true&period=60000"/>
+ <from uri="timer://org.apache.camel.example.loadbalancer?period=10s"/>
<bean ref="service" method="createReport"/>
<to uri="direct:loadbalance"/>
</route>
@@ -39,12 +38,13 @@
<from uri="direct:loadbalance"/>
<loadBalance>
<roundRobin/>
- <to
uri="mina:tcp://localhost:9999?sync=true&allowDefaultCodec=true"/>
- <to
uri="mina:tcp://localhost:9998?sync=true&allowDefaultCodec=true"/>
+ <to
uri="mina:tcp://localhost:9991?sync=true&allowDefaultCodec=true"/>
+ <to
uri="mina:tcp://localhost:9992?sync=true&allowDefaultCodec=true"/>
</loadBalance>
- <to uri="log:org.apache.camel.example?level=INFO"/>
+ <log message="${body}"/>
</route>
</camelContext>
</beans>
+<!-- END SNIPPET: e1 -->
Modified:
camel/trunk/examples/camel-example-loadbalancing/src/main/resources/META-INF/spring/camel-context-mina1.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-loadbalancing/src/main/resources/META-INF/spring/camel-context-mina1.xml?rev=1225170&r1=1225169&r2=1225170&view=diff
==============================================================================
---
camel/trunk/examples/camel-example-loadbalancing/src/main/resources/META-INF/spring/camel-context-mina1.xml
(original)
+++
camel/trunk/examples/camel-example-loadbalancing/src/main/resources/META-INF/spring/camel-context-mina1.xml
Wed Dec 28 12:38:53 2011
@@ -16,8 +16,7 @@
limitations under the License.
-->
-<!-- Configures the Camel Context-->
-
+<!-- START SNIPPET: e1 -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/spring"
@@ -27,16 +26,17 @@
<bean id="service" class="org.apache.camel.example.service.Reporting"/>
- <camelContext xmlns="http://camel.apache.org/schema/spring" trace="false">
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
<route id="mina1">
- <from uri="mina:tcp://localhost:9999"/>
+ <from uri="mina:tcp://localhost:9991"/>
<setHeader headerName="minaServer">
- <constant>localhost:9999</constant>
+ <constant>localhost:9991</constant>
</setHeader>
<bean ref="service" method="updateReport"/>
</route>
</camelContext>
-</beans>
\ No newline at end of file
+</beans>
+<!-- END SNIPPET: e1 -->
Modified:
camel/trunk/examples/camel-example-loadbalancing/src/main/resources/META-INF/spring/camel-context-mina2.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-loadbalancing/src/main/resources/META-INF/spring/camel-context-mina2.xml?rev=1225170&r1=1225169&r2=1225170&view=diff
==============================================================================
---
camel/trunk/examples/camel-example-loadbalancing/src/main/resources/META-INF/spring/camel-context-mina2.xml
(original)
+++
camel/trunk/examples/camel-example-loadbalancing/src/main/resources/META-INF/spring/camel-context-mina2.xml
Wed Dec 28 12:38:53 2011
@@ -16,8 +16,7 @@
limitations under the License.
-->
-<!-- Configures the Camel Context-->
-
+<!-- START SNIPPET: e1 -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/spring"
@@ -27,16 +26,17 @@
<bean id="service" class="org.apache.camel.example.service.Reporting"/>
- <camelContext xmlns="http://camel.apache.org/schema/spring" trace="false">
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
- <route id="mina1">
- <from uri="mina:tcp://localhost:9998"/>
+ <route id="mina2">
+ <from uri="mina:tcp://localhost:9992"/>
<setHeader headerName="minaServer">
- <constant>localhost:9998</constant>
+ <constant>localhost:9992</constant>
</setHeader>
<bean ref="service" method="updateReport"/>
</route>
</camelContext>
-</beans>
\ No newline at end of file
+</beans>
+<!-- END SNIPPET: e1 -->