【问题标题】:Spring cloud stream transform expression syntaxSpring Cloud Stream变换表达式语法
【发布时间】:2017-08-09 17:14:22
【问题描述】:

我正在使用本地 Spring Cloud Dataflow 服务器和 shell 试验 Spring Cloud Stream。我得到了像这样的简单例子

dataflow:>stream create --name test --definition "time --trigger.time-unit=SECONDS | log" --deploy

工作正常,因为我每秒在日志中看到一条消息。

2017-08-09 12:51:30,602  INFO -kafka-listener-1 log-sink:202 - 08/09/17 12:51:30
2017-08-09 12:51:31,603  INFO -kafka-listener-1 log-sink:202 - 08/09/17 12:51:31
2017-08-09 12:51:32,605  INFO -kafka-listener-1 log-sink:202 - 08/09/17 12:51:32
.... more log msgs ....

现在我正在尝试扩展此示例以插入转换。我想每秒在日志中看到一次“hello world”而不是时间,但我不知道如何正确指定表达式。

我试过了:

dataflow:>stream create --name test --definition "time --trigger.time-unit=SECONDS | transform --transformer.expression='hello world' | log" --deploy

还有这个(注意添加“#{}”):

dataflow:>stream create --name test --definition "time --trigger.time-unit=SECONDS | transform --transformer.expression=#{'hello world'} | log" --deploy

但我在转换日志中继续收到错误:

Failed to convert property value of type 'java.lang.String' 
  to required type 'org.springframework.expression.Expression' for 
  property 'expression'; nested exception is 
  org.springframework.core.convert.ConverterNotFoundException: No converter 
  found capable of converting from type [java.lang.String] to type 
  [org.springframework.expression.Expression]

我已经阅读了Spring Expression Language docs(我觉得没有帮助,因为这些示例都是基于 Java 代码的)。例如,我还查看了一些 Spring Cloud Stream test code

我错过了什么?

一旦“hello world”开始工作,我也想从本地 Dataflow Server 的 application.yml 文件中回显一个属性;欢迎提出建议!


更新:我遵循 quick-start 文档了解 1.3.0.M1 里程碑。应用程序已加载

dataflow:>app import --uri http://bit-ly/Bacon-RELEASE-stream-applications-kafka-10-maven 

正如记录的那样。 (注意,为了这篇文章的目的,将 bit.ly 替换为 bit-ly,因为 StackOverflow 不喜欢 bit.ly URL。)当我直接在浏览器中点击 bit.ly URL 并下载文件时,我看到:

source.file=maven://org.springframework.cloud.stream.app:file-source-kafka-10:1.2.0.RELEASE
source.file.metadata=maven://org.springframework.cloud.stream.app:file-source-kafka-10:jar:metadata:1.2.0.RELEASE
source.ftp=maven://org.springframework.cloud.stream.app:ftp-source-kafka-10:1.2.0.RELEASE
....

我应该使用什么 URL 来下载 1.3.0.M1 应用程序? 1.2.0 的应用似乎无法与 1.3.0.M1 服务器一起工作,这是一个问题吗?

【问题讨论】:

  • 要从 shell 插入文字表达式,您需要 \"'hello'\"'''hello'''
  • @GaryRussell,就是这样。我使用了'''hello''' 版本,并且有效。我实际上想过并尝试了壳逃逸,但显然没有击中正确的咒语。如果您将此添加为答案,我会接受。对于像“?”这样的特殊字符我只是反斜杠吗?

标签: spring-boot spring-cloud-stream spring-cloud-dataflow


【解决方案1】:

the documentation 'White space and quote rules'

要从 shell 插入文字表达式,您需要 \"'hello'\" 或 '''hello'''。

【讨论】:

  • 我在过去一天左右阅读的所有文档,但不知何故我错过了这一部分。非常感谢!
【解决方案2】:

您似乎使用了一些旧版本的 SCDF 和所有开箱即用的应用程序。

所有应用在transform中都有类似的内容:

@EnableBinding(Processor.class)
@EnableConfigurationProperties(TransformProcessorProperties.class)
public class TransformProcessorConfiguration {

@EnableBinding 来自 Spring Cloud Stream,其中:

@Configuration
@Import({ BindingServiceConfiguration.class, BindingBeansRegistrar.class, BinderFactoryConfiguration.class,
        SpelExpressionConverterConfiguration.class })
@EnableIntegration
public @interface EnableBinding {

关注SpelExpressionConverterConfiguration。正是这个负责将字符串转换为Expression 属性。

所以,请务必使用最新的Bacon SCSt 应用程序:http://docs.spring.io/spring-cloud-stream-app-starters/docs/Bacon.RELEASE/reference/html/

【讨论】:

  • 要从 shell 插入文字表达式,您需要 \"'hello'\"'''hello'''
猜你喜欢
  • 2023-03-19
  • 2017-03-26
  • 2018-01-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-22
  • 2020-10-24
相关资源
最近更新 更多