Hi,

This is my first attempt at coding a request reply pattern with Camel
(please be gentle :blush:). This is what I want to do: I have a Master and a
Slave class. The Master class sends an sql query to the Slave class. The
latter executes the query, fills the result in a List and then returns that
List to the Master. These classes will be in different hosts in the future.
This is the code of what I have so far:

(does anyone know how to make the <code> tags work?)

The Master class:

<code>

CamelContext context = new DefaultCamelContext();
ConnectionFactory connectionFactory = new
ActiveMQConnectionFactory("tcp://localhost:61616");
context.addComponent("activemq",
ActiveMQComponent.jmsComponentAutoAcknowledge(connectionFactory));
ProducerTemplate template = context.createProducerTemplate();
context.start();
template.requestBody("activemq:queue:test.queue", "select * from clients");
Thread.sleep(1000);
context.stop();

</code>

The Slave class:

<code>

CamelContext context = new DefaultCamelContext();
ConnectionFactory connectionFactory = new
ActiveMQConnectionFactory("tcp://localhost:61616");
context.addComponent("activemq",
ActiveMQComponent.jmsComponentAutoAcknowledge(connectionFactory));
context.addRoutes(new RouteBuilder() {
                public void configure() {
                     from("activemq:queue:test.queue").process(new
Processor() {
                     public void process(Exchange e) {
                            try {
                                DefaultMessage msg = (DefaultMessage)
e.getIn();
                                String clientsQuery = (String)
msg.getBody();
                                List result =
Db.getDbResultList(clientsQuery);
                                e.getOut(true).setBody(result); 
                            } catch(Exception ex) {
                                logger.debug("slave process exception", ex);
                            }
                        }
                    });
                }
            });
            
context.start();

</code>

And that's all I've got.
I realize that the query is received and executed successfully. But I don't
know if the List is returned and I don't know how to read it from the
master.

Thanks in advance.
-- 
View this message in context: 
http://www.nabble.com/request-reply-with-sql-query-tp25958657p25958657.html
Sent from the Camel - Users (activemq) mailing list archive at Nabble.com.

Reply via email to