首页 > 解决方案 > 如何在 from 路由中使用方法变量

问题描述

我想在谓词的选择中使用局部变量,但是,找不到这怎么可能?

先感谢您,

private boolean enableSS;  //enable or disable message delivery

this.enableSS = Boolean.parseBoolean(endpointDescriptor.getEnableSS());

from(fromStr).routeId(routeId)
    .log("Message received ${file:name} for Compression and Encryption " + " from host " + host)
    .unmarshal(pgpVerifyAndDecrypt).split(new ZipSplitter())
    .streaming().convertBodyTo(String.class)
    .wireTap("file:" + fileArchive)
    .choice()
        .when()  //if the enableSS is true or false ?
            .to(toStr)  // Legacy destination
                
            .to("file:" + toStrP); //new destination

我希望能够做类似的事情 - 这怎么做?

.when(enableSS == true)  //if the enableSS is true or false ?
    .to(...

标签: javaroutesapache-camel

解决方案


您可以使用 PredicateBuilder.constant 之类的

 .when(PredicateBuilder.constant("true".equals(yourArgument)))
            ----
  .end()

推荐阅读