英文:
Apache Camel Multiple SQL Statements
问题
我收到一个包含各种内容的消息。我从该消息中生成多个SQL语句并将它们添加到一个列表中。在我之前的实现中,逐一执行这些语句并不是问题,但我无法确定是否可以通过Apache Camel完成相同的操作。简单地说,我想知道是否可以使用Apache Camel执行多个SQL语句?
类似于以下内容吗?
PS:通常每个语句都不同。
from(...).process(new Processor()).to(我猜这就是多个语句放置的地方)
提前感谢。
英文:
I am getting a message that contains various stuff in it. From that message I generate multiple SQL statements and add them in a list. In my previous implementation it was not a problem and I was executing the statements one by one but I could not find whether it is possible or not doing the same thing with apache camel. Simply what I'm asking is, is it possible to execute multiple SQL statements with apache camel?
Something like below?
PS: Each statement is different from each other usually.
`from(...).process(new Processor()).to(THIS IS WHERE MULTIPLE STATEMENTS GOES I ASSUME)`
Thanks in advance.
答案1
得分: 1
使用Recipient List EIP 在运行时动态设置目标端点列表。
稍微修改你的 Processor
并准备好端点的 List
放入头部。
exchange.getIn().setHeader("MyListOfStatements", Arrays.asList(
"sql:将某事插入某处",
"sql:将任何事物插入其他地方"
));
然后将此头部用作 recipientList
中的 Expression
。
from(...).process(new Processor()).recipientList(header("MyListOfStatements"));
英文:
Use Recipient List EIP to set list of target endpoints dynamically at run-time.
Slightly modify your Processor
and prepare List
of endpoints to header.
exchange.getIn().setHeader("MyListOfStatements", Arrays.asList(
"sql:INSERT something INTO somewhere",
"sql:INSERT anything INTO elsewhere"
));
Then use this header as Expression
in recipientList
from(...).process(new Processor()).recipientList(header("MyListOfStatements"));
答案2
得分: 0
你可以使用驼峰循环 EIP,每次循环中你可以使用循环索引从列表中提取 SQL 语句并执行它。
英文:
You can use the camel loop eip and each loop you can use the loop index to fetch the sql statement from the list and execute it.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论