【发布时间】:2018-07-27 07:59:32
【问题描述】:
from("file:src/data?noop=true").to("jms:incomingOrders");
// content-based router
from("jms:incomingOrders")
.choice()
.when(header("CamelFileName").endsWith(".xml"))
.to("jms:xmlOrders")
.when(header("CamelFileName").regex("^.*(csv|csl)$"))
.to("jms:csvOrders")
.otherwise()
.to("jms:badOrders");
from("jms:xmlOrders")
.setHeader("customer", xpath("/order/@customer"))
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
String recipients = "jms:accounting";
//System.out.println("hii1"+recipients);
String customer = exchange.getIn().getHeader("customer", String.class);
//System.out.println("hii2"+customer);
if (customer.equals("honda")) {
recipients += ",jms:production";
//System.out.println("hii3"+recipients);
}
exchange.getIn().setHeader("recipients", recipients);
}
})
.recipientList(header("recipients"));
// test that our route is working
from("jms:accounting").process(new Processor() {
public void process(Exchange exchange) throws Exception {
System.out.println("Accounting received order: "
+ exchange.getIn().getHeader("CamelFileName"));
}
});
from("jms:production").process(new Processor() {
public void process(Exchange exchange) throws Exception {
System.out.println("Production received order: "
+ exchange.getIn().getHeader("CamelFileName"));
}
});
}
});
输入 XML 格式
<?xml version="1.0" encoding="UTF-8"?>
<order name="motor" amount="1000" customer="honda"/>
我是 Apache Camel 的新手,因此请帮助我在此处指导代码。此代码从 Camel in Action 复制而来,并解释了基于相同 EIP 的收件人列表的使用。因此,在基于 xml 和 csv 进行划分后,它被传递给我正在努力使用
的接收者列表设置标题
和
.recipientList(header("recipients"));
因此,如果有人能解释一下流程,将会有所帮助。
【问题讨论】:
标签: apache-camel