[英]Apache Camel validate before insert data with setBody
I have RouteBuilder as below. 我有如下的RouteBuilder。
from("seda:requestQueue").routeId("service_request").log(LoggingLevel.INFO, "Processing STARTED, {body = ${body}")
.setBody(body())
.to("select * from SERVICE_REQUEST WHERE requestType=:#TYPE AND requestDate=:#date AND owner=:#OWNER)
.split(body()).streaming().process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
Map<String, Object> row = exchange.getIn().getBody(Map.class);
if (row == null) {
LOGGER.info("Request is new. No records found.");
return;
}
//Duplicate request. Q(Not sure how to terminate the process with exception)
}
})
.log(LoggingLevel.INFO, "Processing CONTINUE, {body = ${body}")
.setBody(body())
.to("insert into SERVICE_REQUEST (ID,....) ").log(LoggingLevel.INFO, "Processing COMPLETED").end();
I would like to achieve 我想实现
Question: 1. How can I set original request body to insertQuery? 问题:1.如何将原始请求正文设置为insertQuery? As per the above code, body received at seda:requestQueue is not available to to("insert into SERVICE..).
按照上面的代码,在seda:requestQueue收到的正文不可用于(“插入SERVICE ...)。
Your splitter will send out messages with a new body (based on the SQL). 您的拆分器将发送带有新正文的消息(基于SQL)。 So, the body itself cannot be used.
因此,身体本身无法使用。
Instead, before calling the splitter, set the body to a property of the Exchange. 而是,在调用拆分器之前,将主体设置为Exchange的属性。 Then, when you need to use it, read the value of the property.
然后,当您需要使用它时,请读取该属性的值。
.setProperty("mySampleProperty", simple("${body}")
If you need it back as the body, then -- at that point -- set the body to the value that you previously stored in the Exchange property. 如果需要将其作为正文,则在那时-将正文设置为先前存储在Exchange属性中的值。
Here's a similar question: Apache Camel: how store variable for later use 这是一个类似的问题: Apache Camel:如何存储变量以备后用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.