Apache camel 如何与JDBC一起使用ApacheCamel
ApacheCamel 2.12.1 我的路线设置如下:Apache camel 如何与JDBC一起使用ApacheCamel,apache-camel,Apache Camel,ApacheCamel 2.12.1 我的路线设置如下: public void configure() throws Exception { from("direct:start") .process(new AuthorizationHeaderProcessor(configureCreds())) .to(httpSourceEndpoint)
public void configure() throws Exception {
from("direct:start")
.process(new AuthorizationHeaderProcessor(configureCreds()))
.to(httpSourceEndpoint)
.process(new GenerateSQLFromMessageProcessor))
.enrich("jdbc:dataSource", new DBAggregator())
//...do things with result...
public void configure() throws Exception {
from("direct:start")
.process(new AuthorizationHeaderProcessor(configureCreds()))
.to(httpSourceEndpoint)
.setHeader(new BeanExpression(MySQLBean.class, "methodToGenerateSQL")
.enrich("jdbc:dataSource", new DBAggregator())
//...do things with result...
public class DBAggregator implements AggregationStrategy {
@Override
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
Here I have:
oldExchange = the resulting SQL string that methodToGenerateSQL generated
newExchange = the result set from the SQL query
1 HttpSourceEndPoint是来自某个url的get请求
2然后我想使用这个结果按照GenerateSQLFromMessageProcessor生成SQL,它作为JDBC路由的输入提供
我的问题是,在DBAggregator中,通过的参数是:
oldExchange = the raw SQL string that was sent to the JDBC call
newExchange = the result set from the DB query
ie没有来自http源端点的原始消息的迹象,这正是我所期望的聚合工作方式。我应该如何组合这两条流?是GenerateSQLFromMessageProcessor调用消耗了原始消息吗?如果是这样的话,您应该在bean中为一个实例指定SQL吗
编辑
因此,在标题中设置如下:
public void configure() throws Exception {
from("direct:start")
.process(new AuthorizationHeaderProcessor(configureCreds()))
.to(httpSourceEndpoint)
.process(new GenerateSQLFromMessageProcessor))
.enrich("jdbc:dataSource", new DBAggregator())
//...do things with result...
public void configure() throws Exception {
from("direct:start")
.process(new AuthorizationHeaderProcessor(configureCreds()))
.to(httpSourceEndpoint)
.setHeader(new BeanExpression(MySQLBean.class, "methodToGenerateSQL")
.enrich("jdbc:dataSource", new DBAggregator())
//...do things with result...
public class DBAggregator implements AggregationStrategy {
@Override
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
Here I have:
oldExchange = the resulting SQL string that methodToGenerateSQL generated
newExchange = the result set from the SQL query
我的聚合器中的结果如下所示:
public void configure() throws Exception {
from("direct:start")
.process(new AuthorizationHeaderProcessor(configureCreds()))
.to(httpSourceEndpoint)
.process(new GenerateSQLFromMessageProcessor))
.enrich("jdbc:dataSource", new DBAggregator())
//...do things with result...
public void configure() throws Exception {
from("direct:start")
.process(new AuthorizationHeaderProcessor(configureCreds()))
.to(httpSourceEndpoint)
.setHeader(new BeanExpression(MySQLBean.class, "methodToGenerateSQL")
.enrich("jdbc:dataSource", new DBAggregator())
//...do things with result...
public class DBAggregator implements AggregationStrategy {
@Override
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
Here I have:
oldExchange = the resulting SQL string that methodToGenerateSQL generated
newExchange = the result set from the SQL query
问题是我无法访问来自httpSourceEndpoint的原始消息
由于这是一个聚合器,我希望oldExchange是传入消息,而不仅仅是SQL字符串。
毕竟,它是一个聚合器,但我实际上已经丢失了传入的消息-这并不是在丰富内容
谢谢,
Mr Tea将SQL查询字符串放在标题中没有问题。结果是相同的问题-原始消息在聚合器中不可用。您只获得生成的SQL字符串和查询结果,而不是传入消息。然后将传入消息放入头中。你说你使用聚合器?你的代码太不完整,无法理解你在做什么。我已经添加了更多。。。