如何在 from 路由中使用方法变量

huangapple go评论103阅读模式
英文:

how to use a method variable in a from route

问题

  1. 我想在条件判断中使用一个局部变量但是找不到如何实现
  2. 提前感谢您
  3. private boolean enableSS; //启用或禁用消息传递
  4. this.enableSS = Boolean.parseBoolean(endpointDescriptor.getEnableSS());
  5. from(fromStr).routeId(routeId)
  6. .log("接收到消息 ${file:name} 用于压缩和加密,来自主机 ${host}")
  7. .unmarshal(pgpVerifyAndDecrypt).split(new ZipSplitter())
  8. .streaming().convertBodyTo(String.class)
  9. .wireTap("file:" + fileArchive)
  10. .choice()
  11. .when() //如果 enableSS 是 true 还是 false?
  12. .to(toStr) // 传统目标
  13. .to("file:" + toStrP); //新目标

我希望能够做类似以下的操作 - 如何实现?

  1. .when(enableSS == true) //如果 enableSS 是 true 还是 false?
  2. .to(...
英文:

I would like to use a local variable in a choice when predicate, but, can't find how this is possible?

thank you in advance,

  1. private boolean enableSS; //enable or disable message delivery
  2. this.enableSS = Boolean.parseBoolean(endpointDescriptor.getEnableSS());
  3. from(fromStr).routeId(routeId)
  4. .log("Message received ${file:name} for Compression and Encryption " + " from host " + host)
  5. .unmarshal(pgpVerifyAndDecrypt).split(new ZipSplitter())
  6. .streaming().convertBodyTo(String.class)
  7. .wireTap("file:" + fileArchive)
  8. .choice()
  9. .when() //if the enableSS is true or false ?
  10. .to(toStr) // Legacy destination
  11. .to("file:" + toStrP); //new destination

I hope to be able to do something like - how can this be done?

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

答案1

得分: 1

你可以使用 PredicateBuilder.constant,就像这样:

  1. .when(PredicateBuilder.constant("true".equals(yourArgument)))
  2. ----
  3. .end()
英文:

You can use the PredicateBuilder.constant like

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

huangapple
  • 本文由 发表于 2020年10月24日 03:22:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/64506143.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定