Apache Camel 多播 CBR 在多播后无法与处理器一起使用

发布于 2024-12-17 14:20:14 字数 2789 浏览 1 评论 0原文

我完全不知道我做错了什么。下面是两个有效的代码片段。但如果我需要将 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”);
                  }
            }
}

I am completely clueless of what I am doing wrong. Below are the 2 code snippets that works. But if I need to place the processor of snippet-2 in snippet-1 it doesn't work. How can I find out the reason?

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

Working snippet -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”);
                  }
            }
}

Non Working snippet -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”);
                  }
            }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痴骨ら 2024-12-24 14:20:14

这样的事情终于奏效了。

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

            }
        });

Something like this finally worked.

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

            }
        });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文