On Jan 31, 2008, at 11:33 AM, cmdr wrote:

Look at this:

from("file:request.sql").splitter(body(String.class).tokenize("\n"))
.process(new Processor()
{
        public void process(Exchange exchange) throws Exception
        {
                System.out.println(exchange.getIn());
        }
})
.to("jdbc:dataSource")
.process(new Processor()
{
        public void process(Exchange exchange) throws Exception
        {
                System.err.println(exchange.getIn());
        }
});

and

from("file:request.sql").splitter(body(String.class).tokenize("\n"))
.process(new Processor()
{
        public void process(Exchange exchange) throws Exception
        {
                System.out.println(exchange.getIn());
        }
})
.process(new Processor()
{
        public void process(Exchange exchange) throws Exception
        {
                System.err.println(exchange.getIn());
        }
});

In the first example I get 1 output in the System.err.println
In the second example (whithout the to("jdbc:...")) I get all requests

Just so we're clear, the first route will take the output of running each SQL query, and send that on to your second Processor. The second route is just a straight pass-through, because your Processors don't set the exchange's Out message anywhere.

Does the first query successfully execute when you have this problem?

Below is an example that worked for me locally (Mac OS X, MySQL 5), with a few simple count queries in the "statements.sql" file. Does this work for you at all?

---SplitterExplorationTest.java---
import javax.naming.Context;
import javax.sql.DataSource;

import org.apache.camel.ContextTestSupport;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.util.jndi.JndiTest;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

public class SplitterExplorationTest extends ContextTestSupport
{
    public void testSomethingOrOther() throws InterruptedException
    {
final MockEndpoint mock = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
        mock.expectedMessageCount(4);
        mock.assertIsSatisfied();
    }

    @Override
    protected Context createJndiContext() throws Exception
    {
final DataSource ds = new DriverManagerDataSource("com.mysql.jdbc.Driver", "jdbc:mysql:// localhost/activemq", "dev", "dev");
        final Context context = JndiTest.createInitialContext();
        context.bind("myDataSource", ds);
        return context;
    }

    @Override
    protected RouteBuilder createRouteBuilder() throws Exception
    {
        return new RouteBuilder()
        {
            @Override
            public void configure()
            {
from("file:/tmp/camel/ statements sql ").splitter (body (String class ).tokenize ("\n ")).to ("log:preJdbc ").to("jdbc:myDataSource").to("log:postJdbc").to("mock:result");
            }
        };
    }
}

---statements.sql---
select count(*) from activemq_acks
select count(*) from activemq_locks
select count(*) from meddiusmq_msgs
select id from activemq_msgs limit 2

- aaron

Reply via email to