After much effort, I found a way to implement this based on the loadbalancer example provided by apache.
I uploaded the eclipse project to my github account, you can check its work here:
Although my example respects the general intended architecture, it has several differences, as described below:
- It uses Spring DSL instead of Java DSL
- MyApp-A is a loadbalancer. Every 10, it generates a report (instead of reading the file) and sends it to MyApp-B.
- MyApp-B corresponds to MINA 1 server on localhost: 9991
- MyApp-C corresponds to MINA 3 server on localhost: 9993
- MyApp-D corresponds to MINA 2 server on localhost: 9992
- When MyApp-C receives a report, it sends it back to MyApp-A
In addition, it is also unclear when, where, and why MyApp-C responds to MyApp-A with a modified report. This behavior is not specified in the Spring DSL code, and so far no one has been able to explain to me why this is even happening.
Thus, two problems remain:
- How to do it using Java DSL
- Why does MyApp-C respond to MyApp-A and how does it do it?
If you're interested, here is the README.txt I created with the exact description of the problem:
Load balancing with MINA example
This example shows how you can easily use the Camel-MINA component to develop a solution that allows a fail-safe solution that redirects requests when the server is turned off. These servers are simple TCP / IP servers built using the Apache MINA infrastructure run in separate JVMs.
In this example, the load balancer will generate a report every 10 seconds and send this report to the MINA server running on local: 9991. Then this server sends the report to MINA server running on localhost: 9993, which then returns the client report so that it can print it to the console. Each MINA server, modify the message body so that you can see the routes that the report should have used. If for some reason (say you press 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. After this MINA server receives the report he will send it to the MINA server running on localhost: 9993 as nothing happened. If localhost: 9991 returns again, then the loadbalancer will start using it again.
The load balancer will always try to use localhost: 9991 until trying to use localhost: 9992 no matter what.
Running example
To compile and install the project in your maven repo, run the following command in the root of the project
mvn clean install
To run this example, run the following command in the appropriate folder:
minΓ1 and:
mvn exec: java -Pmina1
mina2: mvn exec: java -Pmina2
mina3: mvn exec: java -Pmina3
load balancer: mvn exec: java -Ploadbalancer
If you encounter any problems, let us know on the Camel forum
http://camel.apache.org/discussion-forums.html
Pedro Martins!
EDIT
In a previous post, I had 2 questions: 1. How to do this in java dsl 2. why mini-servers send answers.
In the end, I will attack problem 1, but I just want to say 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. Klaus for the answer and suggestions.
EDIT
Both problems are now resolved, and they are both in the same git repository. Hope my code helps people.