Apache Camel Multicast CBR не работает с процессором после мультикастинга - PullRequest
0 голосов
/ 24 ноября 2011

Я совершенно не понимаю, что я делаю неправильно. Ниже приведены 2 фрагмента кода, которые работают. Но если мне нужно поместить процессор snippet-2 в snippet-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 голосов
/ 25 ноября 2011

Нечто подобное наконец заработало.

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");

            }
        });
...