apache mq - 聚合器未从目标队列上的处理器接收更新的主体

时间:2014-08-19 06:48:04

标签: java apache-camel activemq

我对这些人感到茫然 - 无法弄清楚为什么我的聚合器没有从我正在聚合响应的目标队列上的处理器接收我更新的消息体。在目标队列的处理器中,正文被更新,我可以打印以控制更新的正文而不会出现问题。但是,当我尝试打印以从聚合器控制消息正文时,消息没有在处理器中进行的更新。

这是我的路线:

context.addRoutes(new RouteBuilder(){

        public void configure(){

            from("jms:queue:ready_for_test")
            .multicast(new CompAggregationStrategy())
                .parallelProcessing()
                .to("jms:queue:test1", "jms:queue:test2", "jms:queue:test3")
            .end()
            .to("jms:queue:highest_value");

            from("jms:queue:test1").process(new InstProcessor("Comp1"));
            from("jms:queue:test2").process(new InstProcessor("Comp2"));
            from("jms:queue:test3").process(new InstProcessor("Comp3"));

        }

这是InstProcessor:

    public class InsuranceProcessor implements Processor{

    private String providerName;

    public InsuranceProcessor(String name) {
        this.providerName = name;
    }

    public void process(Exchange e) throws Exception {


        double rate = Double.MAX_VALUE;
        String body = e.getIn().getBody(String.class);
        String[] msgArray = body.split("|");

        //do a bunch of stuff, removed for brevity
        //this stuff calculates rate

        //build out new exchange body
        StringBuilder newExchange = new StringBuilder();
        newExchange.append(body);
        newExchange.append("|");
        newExchange.append((int)rate);

        //replace old exchange body with new exchange body
        e.getIn().setBody(newExchange.toString());

        //System.out.println(newExchange.toString()); //this displays correctly

    }

}

我的聚合器:

    public class CompAggregationStrategy implements AggregationStrategy{
    public Exchange aggregate(Exchange oldExchange, Exchange newExchange){

        //should always be true on first response
        if(oldExchange == null){
            return newExchange;
        }

//both of these lines outputting to console output my original message, without the rate appended to the msg
        //System.out.println(newExchange.getIn().getBody(String.class));
        //System.out.println(oldExchange.getIn().getBody(String.class));

        Double oldQuote = Double.parseDouble(oldExchange.getIn().getBody(String.class).split("|")[11]);
        Double newQuote = Double.parseDouble(newExchange.getIn().getBody(String.class).split("|")[11]);

        if (oldQuote.doubleValue() <= newQuote.doubleValue()) {
            return oldExchange;
        } else {
            return newExchange;
        }

    }

}
我对我的生活无法弄清楚这一点。任何帮助都非常感谢。

0 个答案:

没有答案