/script-transform-processor

A Spring Cloud Streams module for general script evaluation

Primary LanguageJava

Spring Cloud Stream Script Transform Processor

A Spring Cloud Stream module that transforms messages using a script. The language of the script can be specified.

Requirements

  • Java 7 or Above

Code Tour

ScriptTransformProcessorApplication

the Spring Boot Main Application

ScriptTransformProcessor

the actual module code that interacts with message channels

ScriptTransformProcessorProperties

defines the configuration properties that are available to the Script Transform Processor

  • script: the textual form of the script to run

  • language: what language is the script? e.g. groovy/js/ruby

  • variables: variable bindings as a comma delimited string of name-value pairs, e.g. 'foo=bar,baz=car'

  • variablesLocation: the location of a properties file containing custom script variable bindings

Building/Installing with Maven

$> mvn -s .settings.xml clean install

Running the Application

$> java -jar target/script-transform-processor-${version}-exec.jar

Installing in Spring Cloud Dataflow

XD> module register --name scriptable --coordinates org.springframework.cloud.stream.module:script-transform-processor:jar:exec:1.0.0.BUILD-SNAPSHOT --type processor

Using in a Spring Cloud Dataflow stream definition

XD> stream create --deploy true --name demog --definition "time | scriptable --script=\"return payload+'::'+payload\" --language=groovy | log"
XD> stream create --deploy true --name demor --definition "time | scriptable --script=\"return \"\"#{payload.upcase}\"\"\" --language=ruby | log"
XD> stream create --deploy true --name demojs --definition "time | scriptable --script=\"function double(a) {\\n return a+''+a;\\n}\\ndouble(payload);\" --language=js | log"

Python is not currently working but when it does it will look like this!

XD> stream create --deploy true --name demop --definition "time | scriptable --script=\"def concat(x,y):\\n  return x+y\\nanswer = concat(\"\"hello \"\",payload)\\n\" --language=python | log"