173.7. Samples
在以下示例中,我们从 customer 表中获取行。
首先,在 Camel registry 中注册数据源为 testdb :
然后,我们配置路由到 JDBC 组件的路由,以便执行 SQL。请注意,我们如何引用上一步中绑定的 testdb 数据源:
或者您可以在 Spring 中创建数据源,如下所示:
我们创建一个端点,将 SQL 查询添加到 IN 消息的正文,然后发送交换。查询的结果在 OUT 正文中返回:
如果您需要处理一行,而不是使用一个行,而不是整个 ResultSet,您需要使用 Splitter EIP,例如:
from("direct:hello")
// here we split the data from the testdb into new messages one by one
// so the mock endpoint will receive a message per row in the table
// the StreamList option allows to stream the result of the query without creating a List of rows
// and notice we also enable streaming mode on the splitter
.to("jdbc:testdb?outputType=StreamList")
.split(body()).streaming()
.to("mock:result");