Apache Camel Multicast CBR在多片化之后无法与处理器配合使用

时间:2011-11-24 10:55:21

标签: multicast apache-camel

我完全不知道我做错了什么。以下是有效的2个代码段。但是如果我需要将snippet-2的处理器放在片段-1中,它就不起作用了。我怎么能找出原因?

工作片段-1

from("file:inbox")
      .multicast()
      .to("seda:a")
      .choice()
         .when(header("foo").isEqualTo("one"))
         .to("log:org.apache.camel.DeadLetterChannel?level=error")
         .otherwise()
         .to("file://d://log//camel//output1<file:///d://log//camel//output1>")
       .to("seda:b")
        .choice()
        .when(header("foo").isEqualTo("one"))
        .to("log:org.apache.camel.DeadLetterChannel?level=error")
        .otherwise()
        .to("file://d://log//camel//output2<file:///d://log//camel//output2>");

工作片段-2

    from("file:inbox")
      .multicast()
    .process(new MutlicastRecoveryProcessor (“output1”))
                                .to    ("file://d://log//camel//output1<file:///d://log//camel//output1>")
                . process(new MutlicastRecoveryProcessor (“output2”))
                                .to("file://d://log//camel//output2<file:///d://log//camel//output2>");

class MutlicastRecoveryProcessor implements Processor {

private String endpointSeqID;
            public MutlicastRecoveryProcessor(String endpointSeqID) {

                  this.endpointSeqID = endpointSeqID;
            }
            @Override
            public void process(Exchange exchange) throws Exception {

                  if (“output1”.equals(this.endpointSeqID)) {
                      exchange.getIn().setHeader(“foo”,”one”);
                  }
            }
}

非工作片段-1

from("file:inbox")
      .multicast()
.process(new MutlicastRecoveryProcessor (“output1”))
         .to("seda:a")
         .choice()
         .when(header("foo").isEqualTo("one"))
         .to("log:org.apache.camel.DeadLetterChannel?level=error")
         .otherwise()
         .to("file://d://log//camel//output1<file:///d://log//camel//output1>")
.process(new MutlicastRecoveryProcessor (“output2”))
        .to("seda:b")
        .choice()
        .when(header("foo").isEqualTo("one"))
        .to("log:org.apache.camel.DeadLetterChannel?level=error")
        .otherwise()
        .to("file://d://log//camel//output2<file:///d://log//camel//output2>");

class MutlicastRecoveryProcessor implements Processor {

private String endpointSeqID;
            public MutlicastRecoveryProcessor(String endpointSeqID) {

                  this.endpointSeqID = endpointSeqID;
            }
            @Override
            public void process(Exchange exchange) throws Exception {

                  if (“output1”.equals(this.endpointSeqID)) {
                      exchange.getIn().setHeader(“foo”,”one”);
                  }
            }
}

1 个答案:

答案 0 :(得分:0)

这样的事情终于奏效了。

class MutlicastRecoveryProcessor implements Processor {
            private String endpointSeq;

            public MutlicastRecoveryProcessor(String endpointSeq) {
                this.endpointSeq = endpointSeq;
            }

            @Override
            public void process(Exchange exchange) throws Exception {
                if ("output1".equals(this.endpointSeq)) {
                    exchange.getIn().setHeader("foo", "one");
                } else {
                    System.out.println("endpoint " + this.endpointSeq);
                }
            }
        }

        CamelContext context = new DefaultCamelContext();

        context.addRoutes(new RouteBuilder() {

            public void configure() {
                from("file://d://log//camel").convertBodyTo(String.class)
                        .multicast().to("seda:a", "seda:b");

                from("seda:a")
                        .process(new MutlicastRecoveryProcessor("output1"))
                        .choice()
                        .when(header("foo").isEqualTo("one"))
                        .to("log:org.apache.camel.DeadLetterChannel?level=error")
                        .otherwise().to("file://c://log//camel//output1");

                from("seda:b")
                        .process(new MutlicastRecoveryProcessor("output2"))
                        .choice()
                        .when(header("foo").isEqualTo("one"))
                        .to("log:org.apache.camel.DeadLetterChannel?level=error")
                        .otherwise().to("file://d://log//camel//output2");

            }
        });