{"id":57508,"date":"2016-06-21T10:00:53","date_gmt":"2016-06-21T07:00:53","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=57508"},"modified":"2016-06-20T18:16:07","modified_gmt":"2016-06-20T15:16:07","slug":"load-balancing-apache-camel","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2016\/06\/load-balancing-apache-camel.html","title":{"rendered":"Load balancing with Apache Camel"},"content":{"rendered":"<p>In this example we will show you how to use Apache Camel as a load balancer for your system. In computer world a load balancer is a device that acts as a reverse proxy and distributes network or application traffic across a number of servers. Load balancers are used to increase capacity (concurrent users) and reliability of applications. With the help of Camel we can make our own software load balancer in no time. Enjoy riding!<\/p>\n<p>Load balancing is not a separate pattern in Enterprise Integration Patterns book (as Claus Ibsen said it would be if there was a second edition of the book) but Camel treats it just like another EIP. While Camel syntax makes load balancing looks deceivingly easy it&#8217;s still a complicated topic and you should spend some time planning a suitable strategy in design phase. Camel comes with a number of built-in load balancing policies. In this example we cover some of them that are more commonly used.<\/p>\n<p>The codes for this article use Maven 3.3.9, Eclipse Mars 4.5.0 and Apache Camel 2.17.1. Please notice the load balancer API has changed a bit since version 2.15, if you are going to use earlier versions of Camel please consult the documentation. All the classes in this example source code use @Test annotated method, so you have to run them as JUnit tests and hopefully see the green bar.<\/p>\n<h2>1. Creating base\u00a0project<\/h2>\n<p>Before we move on to writing actual codes lets first create a Maven project in Eclipse. First select File -&gt; New&#8230; -&gt; new project. Type maven and select Maven project.<\/p>\n<p><figure id=\"attachment_57523\" aria-describedby=\"caption-attachment-57523\" style=\"width: 511px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/1-create-maven-project.jpg\"><img decoding=\"async\" class=\"size-full wp-image-57523\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/1-create-maven-project.jpg\" alt=\"Create a new maven project\" width=\"511\" height=\"494\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/1-create-maven-project.jpg 511w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/1-create-maven-project-300x290.jpg 300w\" sizes=\"(max-width: 511px) 100vw, 511px\" \/><\/a><figcaption id=\"caption-attachment-57523\" class=\"wp-caption-text\">Create a new maven project<\/figcaption><\/figure><\/p>\n<p>In the next window check the create a simple project option and click next:<\/p>\n<p><figure id=\"attachment_57524\" aria-describedby=\"caption-attachment-57524\" style=\"width: 511px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/2-create-maven-project-2.jpg\"><img decoding=\"async\" class=\"wp-image-57524 size-full\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/2-create-maven-project-2.jpg\" alt=\"Create a simple maven project\" width=\"511\" height=\"469\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/2-create-maven-project-2.jpg 511w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/2-create-maven-project-2-300x275.jpg 300w\" sizes=\"(max-width: 511px) 100vw, 511px\" \/><\/a><figcaption id=\"caption-attachment-57524\" class=\"wp-caption-text\">Create a simple maven project<\/figcaption><\/figure><\/p>\n<p>Finally add the following configuration and click finish:<\/p>\n<p><figure id=\"attachment_57525\" aria-describedby=\"caption-attachment-57525\" style=\"width: 511px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/3-create-maven-project-3.jpg\"><img decoding=\"async\" class=\"size-full wp-image-57525\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/3-create-maven-project-3.jpg\" alt=\"Configure maven project\" width=\"511\" height=\"471\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/3-create-maven-project-3.jpg 511w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/3-create-maven-project-3-300x277.jpg 300w\" sizes=\"(max-width: 511px) 100vw, 511px\" \/><\/a><figcaption id=\"caption-attachment-57525\" class=\"wp-caption-text\">Configure maven project<\/figcaption><\/figure><\/p>\n<p>Now edit the pom.xml file to look as follow:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>pom.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml\">&lt;project xmlns=\"http:\/\/maven.apache.org\/POM\/4.0.0\" xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:schemaLocation=\"http:\/\/maven.apache.org\/POM\/4.0.0 http:\/\/maven.apache.org\/xsd\/maven-4.0.0.xsd\"&gt;\r\n&lt;modelVersion&gt;4.0.0&lt;\/modelVersion&gt;\r\n&lt;groupId&gt;com.javacodegeeks&lt;\/groupId&gt;\r\n&lt;artifactId&gt;camelLoadBalancer&lt;\/artifactId&gt;\r\n&lt;version&gt;1.0.0-SNAPSHOT&lt;\/version&gt;\r\n\r\n    &lt;dependencies&gt;\r\n        &lt;dependency&gt;\r\n            &lt;groupId&gt;org.apache.camel&lt;\/groupId&gt;\r\n            &lt;artifactId&gt;camel-core&lt;\/artifactId&gt;\r\n            &lt;version&gt;2.17.1&lt;\/version&gt;\r\n        &lt;\/dependency&gt;\r\n        &lt;dependency&gt;\r\n            &lt;groupId&gt;org.apache.camel&lt;\/groupId&gt;\r\n            &lt;artifactId&gt;camel-test&lt;\/artifactId&gt;\r\n            &lt;version&gt;2.17.1&lt;\/version&gt;\r\n        &lt;\/dependency&gt;\r\n        &lt;dependency&gt;\r\n            &lt;groupId&gt;junit&lt;\/groupId&gt;\r\n            &lt;artifactId&gt;junit&lt;\/artifactId&gt;\r\n            &lt;version&gt;4.12&lt;\/version&gt;\r\n        &lt;\/dependency&gt;\r\n    &lt;\/dependencies&gt;\r\n&lt;\/project&gt;\r\n<\/pre>\n<h2>2. Load balancing<\/h2>\n<p>We mentioned different policies that Camel support but what are policies? A policy defines how workload is distributed among different receivers (processor, consumer service&#8230;). In this article we sow examples of Random, round robin and their weighted counterparts and topic policies. At the end we show you how to make your own policy.<\/p>\n<h3>2.1. Random<\/h3>\n<p>The simplest form of load balancing policy is random. As the name implies you just define the endpoints that should handle the load and Camel decides which one to use, randomly. Here is the code that implements random policy. m1, m2 and m3 are the endpoints that handle\u00a0the message. The end always receives the message but each time you run the class one of the aforementioned end points is used. This selection is totally random and you can check this randomness by adding your own assertions.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p><span style=\"text-decoration: underline;\"><em>RandomLoadBalance.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.jcg;\r\n\r\nimport org.apache.camel.EndpointInject;\r\nimport org.apache.camel.builder.RouteBuilder;\r\nimport org.apache.camel.component.mock.MockEndpoint;\r\nimport org.apache.camel.test.junit4.CamelTestSupport;\r\nimport org.junit.Test;\r\n\r\npublic class RandomLoadBalance extends CamelTestSupport{\r\n\t@EndpointInject(uri=\"mock:m1\")\r\n\tMockEndpoint m1;\r\n\t@EndpointInject(uri=\"mock:m2\")\r\n\tMockEndpoint m2;\r\n\t@EndpointInject(uri=\"mock:m3\")\r\n\tMockEndpoint m3;\r\n\t@EndpointInject(uri=\"mock:end\")\r\n\tMockEndpoint end;\r\n\r\n\t@Override\r\n\tprotected RouteBuilder createRouteBuilder() throws Exception{\r\n\t\treturn new RouteBuilder(){\r\n\t\t\t@Override\r\n\t\t\tpublic void configure() throws Exception {\r\n\t\t\t\tfrom(\"direct:start\").loadBalance().random().to(m1,m2,m3).end().to(end);\r\n\t\t\t}\r\n\t\t};\r\n\t}\r\n\t\r\n\t@Test\r\n\tpublic void testSending() throws Exception{\r\n\t\tend.expectedMessageCount(1);\r\n\t\ttemplate.sendBody(\"direct:start\", \"\");\r\n\t\tend.assertIsSatisfied();\r\n\t}\r\n}\r\n<\/pre>\n<h3>2.2. Round robin<\/h3>\n<p>Round robin is another simple type of load balancing. In this policy the endpoints are used in turn one by one. In the example code you see the message goes through m1, m2, m3 and again m1.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>RoundRobinLoadBalance.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.jcg;\r\n\r\nimport javax.naming.Context;\r\nimport org.apache.camel.EndpointInject;\r\nimport org.apache.camel.builder.RouteBuilder;\r\nimport org.apache.camel.component.dataset.SimpleDataSet;\r\nimport org.apache.camel.component.mock.MockEndpoint;\r\nimport org.apache.camel.test.junit4.CamelTestSupport;\r\nimport org.junit.Test;\r\n\r\npublic class RoundRobinLoadBalance extends CamelTestSupport{\r\n\t\r\n\t@EndpointInject(uri=\"mock:m1\")\r\n\tMockEndpoint m1;\r\n\t@EndpointInject(uri=\"mock:m2\")\r\n\tMockEndpoint m2;\r\n\t@EndpointInject(uri=\"mock:m3\")\r\n\tMockEndpoint m3;\r\n\t@EndpointInject(uri=\"mock:end\")\r\n\tMockEndpoint end;\r\n\t\r\n\t@Override\r\n\tprotected RouteBuilder createRouteBuilder() throws Exception{\r\n\t\treturn new RouteBuilder(){\r\n\t\t\t@Override\r\n\t\t\tpublic void configure() throws Exception {\r\n\t\t\t\tfrom(\"dataset:start\").loadBalance().roundRobin().to(m1,m2,m3).end().to(end);\r\n\t\t\t}\r\n\t\t};\r\n\t}\r\n\t\r\n\t@Override\r\n\tprotected Context createJndiContext() throws Exception{\r\n\t\tSimpleDataSet sds = new SimpleDataSet();\r\n\t\tsds.setSize(4);\r\n\t\tContext context = super.createJndiContext();\r\n\t\tcontext.bind(\"start\", sds);\r\n\t\treturn context;\r\n\t}\r\n\t\r\n\t@Test\r\n\tpublic void testSending() throws Exception{\t\r\n\t\tm1.expectedMessageCount(2);\r\n\t\tm2.expectedMessageCount(1);\r\n\t\tm3.expectedMessageCount(1);\r\n\t\tend.expectedMessageCount(4);\r\n\t\ttemplate.sendBody(\"dataset:start\", \"\");\r\n\t\tm1.assertIsSatisfied();\r\n\t\tm2.assertIsSatisfied();\r\n\t\tm3.assertIsSatisfied();\r\n\t\tend.assertIsSatisfied();\r\n\t}\r\n}\r\n<\/pre>\n<h3>2.3. Weighted round robin<\/h3>\n<p>In real world it rarely happens that you have some identical machines serving your requests. So it makes sense to have one machine that is probably more powerful does more job than others. Weighted round robin and weighted random are more sophisticated counterparts of round robin and random policies respectively. With weighted round robin (or random) you can control load balancing in a fine-grained manner. Here we give an example of weighted round robin. Weighted random is identical.<\/p>\n<p>The weight method has two arguments. First is a boolean that defines if policy is round robin (true) or random (false). The second argument is a String that defines distribution ratio of the corresponding endpoints. Here &#8220;2,1&#8221; means m1 receives twice as much traffic as m2 receives. In earlier version of Camel you had to use a List of integers.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>WeightedRoundRobinLoadBalance.java<\/em><\/span><\/p>\n<pre class=\"brush:java; wrap-lines:false\">package com.jcg;\r\n\r\nimport javax.naming.Context;\r\nimport org.apache.camel.EndpointInject;\r\nimport org.apache.camel.builder.RouteBuilder;\r\nimport org.apache.camel.component.dataset.SimpleDataSet;\r\nimport org.apache.camel.component.mock.MockEndpoint;\r\nimport org.apache.camel.test.junit4.CamelTestSupport;\r\nimport org.junit.Test;\r\n\r\npublic class WeightedRoundRobinLoadBalance extends CamelTestSupport{\r\n\t\r\n\t@EndpointInject(uri=\"mock:m1\")\r\n\tMockEndpoint m1;\r\n\t@EndpointInject(uri=\"mock:m2\")\r\n\tMockEndpoint m2;\r\n\t@EndpointInject(uri=\"mock:end\")\r\n\tMockEndpoint end;\r\n\t\r\n\t@Override\r\n\tprotected RouteBuilder createRouteBuilder() throws Exception{\r\n\t\treturn new RouteBuilder(){\r\n\t\t\t@Override\r\n\t\t\tpublic void configure() throws Exception {\r\n\t\t\t\t\/\/ first argument of weighted method is a boolean defines if the policy is\r\n\t\t\t\t\/\/ Round robin (true) or Random (false)\r\n\t\t\t\tfrom(\"dataset:start\").loadBalance().weighted(true,\"2,1\").to(m1,m2).end().to(end);\r\n\t\t\t}\r\n\t\t};\r\n\t}\r\n\t\r\n\t@Override\r\n\tprotected Context createJndiContext() throws Exception{\r\n\t\tSimpleDataSet sds = new SimpleDataSet();\r\n\t\tsds.setSize(6);\r\n\t\tContext context = super.createJndiContext();\r\n\t\tcontext.bind(\"start\", sds);\r\n\t\treturn context;\r\n\t}\r\n\t\r\n\t@Test\r\n\tpublic void testSending() throws Exception{\r\n\t\tm1.expectedMessageCount(4);\r\n\t\tm2.expectedMessageCount(2);\r\n\t\tend.expectedMessageCount(6);\r\n\t\ttemplate.sendBody(\"dataset:start\", \"\");\r\n\t\tm1.assertIsSatisfied();\r\n\t\tm2.assertIsSatisfied();\r\n\t\tend.assertIsSatisfied();\r\n\t}\r\n}\r\n<\/pre>\n<h3>2.4. Topic<\/h3>\n<p>Topic is fundamentally different from other policies because all the end points receive the message. In our example code m1, m2 and m3 all process 5 messages and the end endpoint receives 5 messages too. Topic can be useful in guarding against endpoint failures.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>TopicLoadBalance.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.jcg;\r\n\r\nimport javax.naming.Context;\r\nimport org.apache.camel.EndpointInject;\r\nimport org.apache.camel.builder.RouteBuilder;\r\nimport org.apache.camel.component.dataset.SimpleDataSet;\r\nimport org.apache.camel.component.mock.MockEndpoint;\r\nimport org.apache.camel.test.junit4.CamelTestSupport;\r\nimport org.junit.Test;\r\n\r\npublic class TopicLoadBalance extends CamelTestSupport{\r\n\t\r\n\t@EndpointInject(uri=\"mock:m1\")\r\n\tMockEndpoint m1;\r\n\t@EndpointInject(uri=\"mock:m2\")\r\n\tMockEndpoint m2;\r\n\t@EndpointInject(uri=\"mock:m3\")\r\n\tMockEndpoint m3;\r\n\t@EndpointInject(uri=\"mock:end\")\r\n\tMockEndpoint end;\r\n\t\r\n\t@Override\r\n\tprotected RouteBuilder createRouteBuilder() throws Exception{\r\n\t\treturn new RouteBuilder(){\r\n\t\t\t@Override\r\n\t\t\tpublic void configure() throws Exception {\r\n\t\t\t\tfrom(\"dataset:start\").loadBalance().topic().to(m1,m2,m3).end().to(end);\r\n\t\t\t}\r\n\t\t};\r\n\t}\r\n\t\r\n\t@Override\r\n\tprotected Context createJndiContext() throws Exception{\r\n\t\tSimpleDataSet sds = new SimpleDataSet();\r\n\t\tsds.setSize(5);\r\n\t\tContext context = super.createJndiContext();\r\n\t\tcontext.bind(\"start\", sds);\r\n\t\treturn context;\r\n\t}\r\n\t\r\n\t@Test\r\n\tpublic void testSending() throws Exception{\t\r\n\t\tm1.expectedMessageCount(5);\r\n\t\tm2.expectedMessageCount(5);\r\n\t\tm3.expectedMessageCount(5);\r\n\t\tend.expectedMessageCount(5);\r\n\t\ttemplate.sendBody(\"dataset:start\", \"\");\r\n\t\tm1.assertIsSatisfied();\r\n\t\tm2.assertIsSatisfied();\r\n\t\tm3.assertIsSatisfied();\r\n\t\tend.assertIsSatisfied();\r\n\t}\r\n}\r\n<\/pre>\n<h3>2.5. Custom load balancer<\/h3>\n<p>Camel offers many useful policies but there are always times when none of them fulfill your needs.\u00a0In such situations you have to define your own load balancing strategy and still Camel doesn&#8217;t leave you alone. Custom load balancer lets you define your own policy easily. In the example code we define a load balancer that checks the message header &#8220;sessionID&#8221; field. If it is even it sends it to m1, if odd to m2. Of course this is an unrealistic example but we deliberately made it simple to be able to focus on load balancing implementation free of business logic clutter. First we make a class that extends LoadBalancerSupport class and override process method. Then we pass an instance of this class to loadBalance method.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>SessionChecker.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.jcg;\r\n\r\nimport org.apache.camel.AsyncCallback;\r\nimport org.apache.camel.Exchange;\r\nimport org.apache.camel.processor.loadbalancer.LoadBalancerSupport;\r\n\r\npublic class SessionChecker extends LoadBalancerSupport{\r\n\r\n\t@Override\r\n\tpublic boolean process(Exchange exchange, AsyncCallback callback) {\r\n\t\t\r\n\t\tint id = exchange.getIn().getHeader(\"sessionID\", Integer.class);\r\n\t\ttry{\r\n\t\t\tif(id%2 == 0){\r\n\t\t\t\tgetProcessors().get(0).process(exchange);\r\n\t\t\t} else{\r\n\t\t\t\tgetProcessors().get(1).process(exchange);\r\n\t\t\t}\r\n\t\t}catch(Exception e){\r\n\t\t\te.printStackTrace();\r\n\t\t}\r\n\t\tcallback.done(true);\r\n\t\treturn true;\r\n\t}\r\n}\r\n<\/pre>\n<p><span style=\"text-decoration: underline;\"><em>CustomLoadBalance.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.jcg;\r\n\r\nimport java.util.HashMap;\r\nimport java.util.Map;\r\nimport javax.naming.Context;\r\nimport org.apache.camel.EndpointInject;\r\nimport org.apache.camel.builder.RouteBuilder;\r\nimport org.apache.camel.component.dataset.SimpleDataSet;\r\nimport org.apache.camel.component.mock.MockEndpoint;\r\nimport org.apache.camel.test.junit4.CamelTestSupport;\r\nimport org.junit.Test;\r\n\r\npublic class CustomLoadBalance extends CamelTestSupport{\r\n\t\r\n\t@EndpointInject(uri=\"mock:m1\")\r\n\tMockEndpoint m1;\r\n\t@EndpointInject(uri=\"mock:m2\")\r\n\tMockEndpoint m2;\r\n\t@EndpointInject(uri=\"mock:end\")\r\n\tMockEndpoint end;\r\n\t\r\n\t@Override\r\n\tprotected RouteBuilder createRouteBuilder() throws Exception{\r\n\t\treturn new RouteBuilder(){\r\n\t\t\t@Override\r\n\t\t\tpublic void configure() throws Exception {\r\n\t\t\t\tfrom(\"dataset:start\").loadBalance(new SessionChecker()).to(m1,m2).end().to(end);\r\n\t\t\t}\r\n\t\t};\r\n\t}\r\n\t\r\n\t@Override\r\n\tprotected Context createJndiContext() throws Exception{\r\n\t\tSimpleDataSet sds = new SimpleDataSet();\r\n\t\tMap&lt;String, Object&gt; headers = new HashMap&lt;&gt;();\r\n\t\theaders.put(\"sessionID\", 1);\r\n\t\tsds.setDefaultHeaders(headers);\r\n\t\tsds.setSize(2);\r\n\t\tContext context = super.createJndiContext();\r\n\t\tcontext.bind(\"start\", sds);\r\n\t\treturn context;\r\n\t}\r\n\t\r\n\t@Test\r\n\tpublic void testSending() throws Exception{\t\r\n\t\tm1.expectedMessageCount(0);\r\n\t\tm2.expectedMessageCount(2);\r\n\t\tend.expectedMessageCount(2);\r\n\t\ttemplate.sendBody(\"dataset:start\", \"\");\r\n\t\tm1.assertIsSatisfied();\r\n\t\tm2.assertIsSatisfied();\r\n\t\tend.assertIsSatisfied();\r\n\t}\r\n}\r\n<\/pre>\n<h2>3. Conclusion<\/h2>\n<p>Still there&#8217;s more into Camel load balancing. We didn&#8217;t cover policies such as Failover, Sticky and Circuit breaker. In fact Camel goes beyond this. You can use load balancing in many more situations such as an HTTP proxy between client and server.<\/p>\n<h2>4. Download the\u00a0Eclipse project<\/h2>\n<p>This was an example of different Camel load balancing policies.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/CamelLoadBalancer.zip\"><strong>Camel load balancer<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this example we will show you how to use Apache Camel as a load balancer for your system. In computer world a load balancer is a device that acts as a reverse proxy and distributes network or application traffic across a number of servers. Load balancers are used to increase capacity (concurrent users) and &hellip;<\/p>\n","protected":false},"author":1025,"featured_media":52,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[357,1200,391],"class_list":["post-57508","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-apache-camel","tag-java","tag-load-balancing"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Load balancing with Apache Camel - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In this example we will show you how to use Apache Camel as a load balancer for your system. In computer world a load balancer is a device that acts as a\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2016\/06\/load-balancing-apache-camel.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Load balancing with Apache Camel - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In this example we will show you how to use Apache Camel as a load balancer for your system. In computer world a load balancer is a device that acts as a\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2016\/06\/load-balancing-apache-camel.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/hessam.shafiemoqaddam\" \/>\n<meta property=\"article:published_time\" content=\"2016-06-21T07:00:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/apache-camel-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Hessam Moqaddam\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@hessamshm\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Hessam Moqaddam\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/06\\\/load-balancing-apache-camel.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/06\\\/load-balancing-apache-camel.html\"},\"author\":{\"name\":\"Hessam Moqaddam\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/2a85684b12cf1a9df3599d1841d4683b\"},\"headline\":\"Load balancing with Apache Camel\",\"datePublished\":\"2016-06-21T07:00:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/06\\\/load-balancing-apache-camel.html\"},\"wordCount\":917,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/06\\\/load-balancing-apache-camel.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/apache-camel-logo.jpg\",\"keywords\":[\"Apache Camel\",\"Java\",\"Load Balancing\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/06\\\/load-balancing-apache-camel.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/06\\\/load-balancing-apache-camel.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/06\\\/load-balancing-apache-camel.html\",\"name\":\"Load balancing with Apache Camel - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/06\\\/load-balancing-apache-camel.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/06\\\/load-balancing-apache-camel.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/apache-camel-logo.jpg\",\"datePublished\":\"2016-06-21T07:00:53+00:00\",\"description\":\"In this example we will show you how to use Apache Camel as a load balancer for your system. In computer world a load balancer is a device that acts as a\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/06\\\/load-balancing-apache-camel.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/06\\\/load-balancing-apache-camel.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/06\\\/load-balancing-apache-camel.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/apache-camel-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/apache-camel-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/06\\\/load-balancing-apache-camel.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Load balancing with Apache Camel\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/2a85684b12cf1a9df3599d1841d4683b\",\"name\":\"Hessam Moqaddam\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0353940004b87857eeb88edd39818f2d7cc2fb03fd4ff59030c954fd436a1c54?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0353940004b87857eeb88edd39818f2d7cc2fb03fd4ff59030c954fd436a1c54?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0353940004b87857eeb88edd39818f2d7cc2fb03fd4ff59030c954fd436a1c54?s=96&d=mm&r=g\",\"caption\":\"Hessam Moqaddam\"},\"description\":\"Started with .NET but quickly moved to the Java world. Now works for a company that provides insurance solutions. His main area of interest is core Java and data structures and algorithms.\",\"sameAs\":[\"http:\\\/\\\/www.javacodegeeks.com\\\/\",\"https:\\\/\\\/www.facebook.com\\\/hessam.shafiemoqaddam\",\"www.linkedin.com\\\/in\\\/hessamshm\",\"https:\\\/\\\/x.com\\\/hessamshm\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/hessam-moqaddam\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Load balancing with Apache Camel - Java Code Geeks","description":"In this example we will show you how to use Apache Camel as a load balancer for your system. In computer world a load balancer is a device that acts as a","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2016\/06\/load-balancing-apache-camel.html","og_locale":"en_US","og_type":"article","og_title":"Load balancing with Apache Camel - Java Code Geeks","og_description":"In this example we will show you how to use Apache Camel as a load balancer for your system. In computer world a load balancer is a device that acts as a","og_url":"https:\/\/www.javacodegeeks.com\/2016\/06\/load-balancing-apache-camel.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_author":"https:\/\/www.facebook.com\/hessam.shafiemoqaddam","article_published_time":"2016-06-21T07:00:53+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/apache-camel-logo.jpg","type":"image\/jpeg"}],"author":"Hessam Moqaddam","twitter_card":"summary_large_image","twitter_creator":"@hessamshm","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Hessam Moqaddam","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2016\/06\/load-balancing-apache-camel.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2016\/06\/load-balancing-apache-camel.html"},"author":{"name":"Hessam Moqaddam","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/2a85684b12cf1a9df3599d1841d4683b"},"headline":"Load balancing with Apache Camel","datePublished":"2016-06-21T07:00:53+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2016\/06\/load-balancing-apache-camel.html"},"wordCount":917,"commentCount":1,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2016\/06\/load-balancing-apache-camel.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/apache-camel-logo.jpg","keywords":["Apache Camel","Java","Load Balancing"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2016\/06\/load-balancing-apache-camel.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2016\/06\/load-balancing-apache-camel.html","url":"https:\/\/www.javacodegeeks.com\/2016\/06\/load-balancing-apache-camel.html","name":"Load balancing with Apache Camel - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2016\/06\/load-balancing-apache-camel.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2016\/06\/load-balancing-apache-camel.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/apache-camel-logo.jpg","datePublished":"2016-06-21T07:00:53+00:00","description":"In this example we will show you how to use Apache Camel as a load balancer for your system. In computer world a load balancer is a device that acts as a","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2016\/06\/load-balancing-apache-camel.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2016\/06\/load-balancing-apache-camel.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2016\/06\/load-balancing-apache-camel.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/apache-camel-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/apache-camel-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2016\/06\/load-balancing-apache-camel.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Load balancing with Apache Camel"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/2a85684b12cf1a9df3599d1841d4683b","name":"Hessam Moqaddam","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/0353940004b87857eeb88edd39818f2d7cc2fb03fd4ff59030c954fd436a1c54?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/0353940004b87857eeb88edd39818f2d7cc2fb03fd4ff59030c954fd436a1c54?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/0353940004b87857eeb88edd39818f2d7cc2fb03fd4ff59030c954fd436a1c54?s=96&d=mm&r=g","caption":"Hessam Moqaddam"},"description":"Started with .NET but quickly moved to the Java world. Now works for a company that provides insurance solutions. His main area of interest is core Java and data structures and algorithms.","sameAs":["http:\/\/www.javacodegeeks.com\/","https:\/\/www.facebook.com\/hessam.shafiemoqaddam","www.linkedin.com\/in\/hessamshm","https:\/\/x.com\/hessamshm"],"url":"https:\/\/www.javacodegeeks.com\/author\/hessam-moqaddam"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/57508","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/1025"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=57508"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/57508\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/52"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=57508"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=57508"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=57508"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}