[英]Apache Camel validate before insert data with setBody
我有如下的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();
我想实现
问题:1.如何将原始请求正文设置为insertQuery? 按照上面的代码,在seda:requestQueue收到的正文不可用于(“插入SERVICE ...)。
您的拆分器将发送带有新正文的消息(基于SQL)。 因此,身体本身无法使用。
而是,在调用拆分器之前,将主体设置为Exchange的属性。 然后,当您需要使用它时,请读取该属性的值。
.setProperty("mySampleProperty", simple("${body}")
如果需要将其作为正文,则在那时-将正文设置为先前存储在Exchange属性中的值。
这是一个类似的问题: Apache Camel:如何存储变量以备后用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.