我有如下的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属性中的值。