camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "pmp.martins" <pmp.mart...@campus.fct.unl.pt>
Subject Basic Apache-Camel LoadBalancer-Failover Example
Date Sat, 02 Nov 2013 19:16:09 GMT
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-Camel with
ActiveMQ as a broker and using jms-component as a client of a loadbalancer
using the failover construct. All this is done using the Java DSL only (if
possible).

The example consists of 4 main apps, called MyApp-A, MyApp-B, MyApp-C and
MyApp-D. In a normal scenario MyApp-A reads a file from my computer and then
transforms it into a message. Then it sends that message to MyApp-B and
MyApp-B sends it to MyApp-C. 

<http://camel.465427.n5.nabble.com/file/n5742551/E73ej.jpg> 

However, there is a fail scenario. In this scenario, MyApp-A fails to send
the message to MyApp-B. It then send the message to MyApp-D, which in turn
sends it to MyApp-C.

<http://camel.465427.n5.nabble.com/file/n5742551/KmRVz.jpg> 

Bellow is the my code for MyApp-A (PS: Is there a way to naturally embed
code here?)

    public class MyApp-A {
    
        public static void main(String args[]) throws Exception {
            // create CamelContext
            CamelContext context = new DefaultCamelContext();
            
            // connect to embedded ActiveMQ JMS broker
            ConnectionFactory connectionFactory = 
                new ActiveMQConnectionFactory("vm://localhost");
            context.addComponent("jms",
               
JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
    
            // add our route to the CamelContext
            context.addRoutes(new RouteBuilder() {
                @Override
                public void configure() {
                   
from("file:data/inbox?noop=true")loadbalancer().failover().to("MyApp-B:incomingOrders").to("MyApp-D:incomingOrders").end();
                }
            });
    
            // start the route and let it do its work
            context.start();
            Thread.sleep(10000);
    
            // stop the CamelContext
            context.stop();
        }
    }



I have considered using the [camel-ftp](http://camel.apache.org/ftp.html)
but it would not work because MyApp-C would not know that MyApp-B died and
would not know that it had to fetch from MyApp-D.

Now I have several problems and questions:

1. How do I send a message (in this case, the file) from MyApp-A to MyApp-B
which is a different application? What should I actually put in the
`.to(String)` method of the Java DSL?
2. How do I actually code MyApp-B? How do I make it receive a message from A
(which is a different application, possibly in a different machine) and send
it to MyApp-C (I assume that if I find out how to send from MyApp-A to
MyApp-B, I will know how to send from MyApp-B to MyApp-C)?
3. How will MyApp-A detect that MyApp-B failed?
4. Which camel component should I use? 

If you could provide any feedback on my code and on how to fix the problem I
would be more then grateful.



--
View this message in context: http://camel.465427.n5.nabble.com/Basic-Apache-Camel-LoadBalancer-Failover-Example-tp5742551.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Mime
View raw message