Basic Apache Camel LoadBalancer Failover Example

后端 未结 1 1255
青春惊慌失措
青春惊慌失措 2021-01-13 02:21

To start I just want to let you know I am new to Camel and very recently I grasped its main concepts.

I am trying to create a basic working example using Apache-Came

相关标签:
1条回答
  • 2021-01-13 02:57

    After much effort, I have found a way to implement this basing myself on the loadbalancer example provided by apache.

    I have uploadded the eclipse project to my github account, you can check it working here:

    • https://github.com/Fl4m3Ph03n1x/stackoverflow/tree/master/loadbalancer-failover-springdsl-example

    Although my example does respect the overall intended architecture, it does have few differences as explained bellow:

    • It uses the Spring DSL instead of the Java DSL
    • MyApp-A is the loadbalancer. Every 10 it generates a report (instead of reading a file) and it sends it to MyApp-B.
    • MyApp-B corresponds to MINA server 1 on localhost:9991
    • MyApp-C corresponds to MINA server 3 on localhost:9993
    • MyApp-D corresponds to MINA server 2 on localhost:9992
    • When MyApp-C receives the report, it sends it back to MyApp-A

    Furthermore, it is also not clear when, where or why MyApp-C replies to MyApp-A with the changed report. This behavior is not specified in the Spring DSL code and so far no one was able to explain to me why this is even happening.

    So two problems remain:

    1. How would this be done using the Java DSL
    2. Why is the MyApp-C replying to MyApp-A and how is it doing it?

    In case you are interested, Here is the README.txt I created, with an accurate description of the problem:

    Load balancing with MINA Example

    This example shows how you can easily use the Camel-MINA component to design a solution allowing for a fault tolerant solution that redirects requests when a server is down. These servers are simple TCP/IP servers created by the Apache MINA framework and run in separate JVMs.

    In this example, the load balancer client will generate a report every 10 seconds and send that report to the MINA server running on localhost:9991. This server then forwards the report to the MINA server running on localhost:9993, which then returns the report to the client so it can print it on the console. Each MINA server will change the body of the message so you can see the routes that the report had to use. If for some reason (lets say you pressed CTRL+C), the MINA server running on localhost:9991 is dead, then the loadbalancer will automatically start using the MINA server running on localhost:9992. Once the this MINA server receives the report, it will send it back to the MINA server running on localhost:9993 like nothing has ever happened. If localhost:9991 gets back up again, then the loadbalancer will start using it again.

    The load balancer will always attempt to use localhost:9991 before trying to use localhost:9992 no matter what.

    Running the example

    To compile and install the project in your maven repo, execute the following command on the root of the project

    mvn clean install

    To run the example, then execute the following command in the respective folder:

    mina1:
    mvn exec:java -Pmina1

    mina2: mvn exec:java -Pmina2

    mina3: mvn exec:java -Pmina3

    loadbalancing: mvn exec:java -Ploadbalancer

    If you hit any problems please let us know on the Camel Forums
    http://camel.apache.org/discussion-forums.html


    Pedro Martins !


    EDIT

    In the previous post I had 2 questions: 1. how to do this in java dsl 2. why are the mina servers sending replies.

    I will attack problem 1 eventually, but I just want to state that the solution to problem 2 is here: http://camel.465427.n5.nabble.com/Load-balancing-using-Mina-example-with-Java-DSL-td5742566.html#a5742585

    Kudos to Mr. Claus for the answer and suggestions.


    EDIT

    Both problems are now solved and they are both in the same git repository. I hope my code helps people.

    0 讨论(0)
提交回复
热议问题