2017-08-09 27 views
0

我正在使用本地Spring雲數據流服務器和shell來試驗Spring Cloud Stream。我已經得到了簡單的例子,像這樣Spring雲流轉換表達式語法

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'的工作,我想從本地數據流服務器的application.yml文件中回顯一個屬性;建議歡迎!


更新:我跟着quick-start文檔的1.3.0.M1里程碑。這些應用程序已加載

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

就像記錄。 (注意,由於StackOverflow不喜歡bit.ly URL,因此爲了這篇文章的目的,用bit-ly替換bit.ly。)當我在瀏覽器中直接點擊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服務器嗎?

+1

要從shell中插入文字表達式,您需要'\''hello'\「'或''''hello''''。 –

+0

@GaryRussell,就是這樣。我使用了''''hello'''版本並且可行。我實際上想過並嘗試shell逃脫,但顯然沒有擊中正確的咒語。如果您將此添加爲答案,我會接受它。對於像'?'這樣的特殊字符我只是反斜槓嗎? – user944849

回答

1

看起來像你使用一些舊版本的SCDF和所有那些開箱即用的應用程序。

所有的應用程序已在transform是這樣的:

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

@EnableBinding來自春天的雲流與:

@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/

+0

感謝您的指針;我更新了我的問題。 – user944849

+0

要從shell中插入文字表達式,您需要使用'\「'hello'\」'或''''hello''''。 –