Apache Camel中的setHeader和receiverList有什么用?

时间:2018-07-27 07:59:32

标签: apache-camel

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进行划分之后,将其传递给我在使用

时遇到困难的收件人列表
  

setHeader

  

.recipientList(header(“ recipients”));;

因此,如果有人可以向我解释流程,这将有所帮助。

0 个答案:

没有答案