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

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

how to use a method variable in a from route

问题

我想在条件判断中使用一个局部变量但是找不到如何实现

提前感谢您

private boolean enableSS;  //启用或禁用消息传递

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

from(fromStr).routeId(routeId)
	.log("接收到消息 ${file:name} 用于压缩和加密,来自主机 ${host}")
	.unmarshal(pgpVerifyAndDecrypt).split(new ZipSplitter())
	.streaming().convertBodyTo(String.class)
	.wireTap("file:" + fileArchive)
	.choice()
		.when()  //如果 enableSS 是 true 还是 false?
			.to(toStr)  // 传统目标
				
			.to("file:" + toStrP); //新目标

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

.when(enableSS == true)  //如果 enableSS 是 true 还是 false?
    .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,

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

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

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

答案1

得分: 1

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

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

You can use the PredicateBuilder.constant like

 .when(PredicateBuilder.constant("true".equals(yourArgument)))
            ----
  .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:

确定