Quantcast

Load balancing using Mina example with Java DSL

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Load balancing using Mina example with Java DSL

pmp.martins
So, recently I started learning Camel. As part of the process I decided to go through all the examples (listed HERE and available when you DOWNLOAD the package with all the examples and docs) and to see what I could learn.

One of the examples, Load Balancing using Mina caught my attention because it uses a Mina in different JVM's and it simulates a load balancer with round robin.

I have a few problems with this example. First it uses the Spring DSL, instead of the Java DSL which my project uses and which I find a lot easier to understand now (mainly also because I am used to it). So the first question: is there a version of this example using only the Java DSL instead of the Spring DSL for the routes and the beans?

My second questions is code related. The description states, and I quote:

<blockquote cite="http://camel.apache.org/loadbalancing-mina-example.html">
Within this demo every ten seconds, a Report object is created from the Camel load balancer server.
This object is sent by the Camel load balancer to a MINA server where the object is then serialized.
One of the two MINA servers (localhost:9991 and localhost:9992) receives the object and enriches
the message by setting the field reply of the Report object. The reply is sent back by the MINA
server to the client, which then logs the reply on the console.
</blockquote> 

So, from what I read, I understand that the MINA server 1 (per example) receives a report from the loadbalancer, changes it, and then it sends that report back to some invisible client. Upon checking the code, I see no client java class or XML and when I run, the server simply posts the results on the command line. Where is the client ?? What is this client?

In the MINA 1server code presented here:

<code>

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

    <route id="mina1">
      <from uri="mina:tcp://localhost:9991"/>
      <setHeader headerName="minaServer">
        <constant>localhost:9991</constant>
      </setHeader>
      <bean ref="service" method="updateReport"/>
    </route>

  </camelContext>

</beans>

</code>

I don't understand how the updateReport method magically prints the object on my console. What if I wanted to send message to a third MINA server? How would I do it? (I would have to add a new route, and send it to the URI of the 3rd server correct?)

I know most of these questions may sound dumb, but I would appreciate if anyone could help me. A Java DSL version of this would really help me.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Load balancing using Mina example with Java DSL

Willem.Jiang
Hi,  

The magic is happened in the camel-context-loadbalancer.xml.
The client is not tcp client, it is just a camel client which can send the request to direct:loadbalance endpoint.
If you want to add third mina endpoint, you can modify the file of camel-context-loadbalancer.xml.

--  
Willem Jiang

Red Hat, Inc.
Web: http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem





On Monday, November 4, 2013 at 5:42 AM, pmp.martins wrote:

> So, recently I started learning Camel. As part of the process I decided to go
> through all the examples (listed HERE
> <http://camel.apache.org/examples.html> and available when you DOWNLOAD
> <http://camel.apache.org/download.html> the package with all the examples
> and docs) and to see what I could learn.  
>  
> One of the examples, Load Balancing using Mina
> <http://camel.apache.org/loadbalancing-mina-example.html> caught my
> attention because it uses a Mina in different JVM's and it simulates a load
> balancer with round robin.  
>  
> I have a few problems with this example. First it uses the Spring DSL,
> instead of the Java DSL which my project uses and which I find a lot easier
> to understand now (mainly also because I am used to it). So the first
> question: is there a version of this example using only the Java DSL instead
> of the Spring DSL for the routes and the beans?
>  
> My second questions is code related. The description states, and I quote:
>  
> <blockquote cite="http://camel.apache.org/loadbalancing-mina-example.html">
> Within this demo every ten seconds, a Report object is created from the
> Camel load balancer server.
> This object is sent by the Camel load balancer to a MINA server where the
> object is then serialized.
> One of the two MINA servers (localhost:9991 and localhost:9992) receives the
> object and enriches  
> the message by setting the field reply of the Report object. The reply is
> sent back by the MINA  
> server to the client, which then logs the reply on the console.
> </blockquote>  
>  
> So, from what I read, I understand that the MINA server 1 (per example)
> receives a report from the loadbalancer, changes it, and then it sends that
> report back to some invisible client. Upon checking the code, I see no
> client java class or XML and when I run, the server simply posts the results
> on the command line. Where is the client ?? What is this client?
>  
> In the MINA 1server code presented here:
>  
> <code>
>  
> <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.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">
>  
> <route id="mina1">
> <from uri="mina:tcp://localhost:9991"/>
> <setHeader headerName="minaServer">
> <constant>localhost:9991</constant>
> </setHeader>
> <bean ref="service" method="updateReport"/>
> </route>
>  
> </camelContext>
>  
> </beans>
>  
> </code>
>  
> I don't understand how the updateReport method magically prints the object
> on my console. What if I wanted to send message to a third MINA server? How
> would I do it? (I would have to add a new route, and send it to the URI of
> the 3rd server correct?)
>  
> I know most of these questions may sound dumb, but I would appreciate if
> anyone could help me. A Java DSL version of this would really help me.
>  
>  
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/Load-balancing-using-Mina-example-with-Java-DSL-tp5742566.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Load balancing using Mina example with Java DSL

pmp.martins
I already modifed the example and it now works a little bit like the request made HERE.

However, I still don't understand how the loadbalancer is getting the replies. Yes, it does send the report to the direct:loadbalance URI, but then it picks it up and sends it to the MINA servers:

<route id="loadbalancer">
                        <from uri="direct:loadbalance" />
                        <loadBalance inheritErrorHandler="false">
                                <failover />
                                <to uri="mina:tcp://localhost:9991?sync=true" />
                                <to uri="mina:tcp://localhost:9992?sync=true" />
                        </loadBalance>
                        <log message="${body}" />
                </route>

In the MINA server's code, the servers are not explicitly sending anything to the loadbalancer.
And in the loadbalancer, the only thing that is done is using the failvoer construct.

There is not one single place in the code, where I actually see explicitly what is going on, and to me, this is quite confusing.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Load balancing using Mina example with Java DSL

Claus Ibsen-2
The load balancer example is doing request/reply messaging (aka
MessageExchangePattern (MEP) = InOut)
http://camel.apache.org/request-reply.html

The mina endpoint on the "other side" is configured with sync=true,
which tells the Mina consumer that a reply message should be sent
back, which is the message when the Camel route is "done".

I suggest you learn about more background about Apache Camel such as
reading this article
http://java.dzone.com/articles/open-source-integration-apache

And then you can take a look at some of the Enterprise Integration
Patterns (EIP)s that Camel offers
http://camel.apache.org/eip
.. for example the event message vs request/reply, and the load balancer eip.

And then look at the mina component as that is used in the example
http://camel.apache.org/mina

And there is also many 3rd party articles and blogs that can introduce
you to Camel or talk about specific use-cases
http://camel.apache.org/articles


And if you want to go more hard-core with Camel then consider some of
these books
http://camel.apache.org/books

... and later this year a 4th Camel book hit the market
http://www.packtpub.com/apache-camel-developers-cookbook/book



On Mon, Nov 4, 2013 at 12:10 PM, pmp.martins
<[hidden email]> wrote:

> I already modifed the example and it now works a little bit like the request
> made  HERE
> <http://camel.465427.n5.nabble.com/Basic-Apache-Camel-LoadBalancer-Failover-Example-td5742551.html>
> .
>
> However, I still don't understand how the loadbalancer is getting the
> replies. Yes, it does send the report to the direct:loadbalance URI, but
> then it picks it up and sends it to the MINA servers:
>
> <route id="loadbalancer">
>                         <from uri="direct:loadbalance" />
>                         <loadBalance inheritErrorHandler="false">
>                                 <failover />
>                                 <to uri="mina:tcp://localhost:9991?sync=true" />
>                                 <to uri="mina:tcp://localhost:9992?sync=true" />
>                         </loadBalance>
>                         <log message="${body}" />
>                 </route>
>
> In the MINA server's code, the servers are not explicitly sending anything
> to the loadbalancer.
> And in the loadbalancer, the only thing that is done is using the failvoer
> construct.
>
> There is not one single place in the code, where I actually see explicitly
> what is going on, and to me, this is quite confusing.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Load-balancing-using-Mina-example-with-Java-DSL-tp5742566p5742585.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



--
Claus Ibsen
-----------------
Red Hat, Inc.
Email: [hidden email]
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Load balancing using Mina example with Java DSL

pmp.martins
Awesome suggestions, I will definitely check out those books !
Loading...