0

Basically looking to parameterize the selected groovy transformation file based on message characteristics...

Something like this:

stream create --name DynamicTestStream --definition "http | transform --script='file:/tmp/groovy/#jsonPath(payload,'$.SELECTOR')/transform.groovy' | log"

This errors out as the script is not running through an evaluation step.

Any suggestions?

Thanks, Mark

2 Answers2

1

Right - this won't work. You could possibly have your groovy script be a master that routes to the selector script, e.g. Including a groovy script in another groovy or delegate to internal classes or functions.

Community
  • 1
  • 1
dturanski
  • 1,723
  • 1
  • 13
  • 8
  • Thanks for the info. I will check out that groovy script approach. However, do you think if I made changes to the included groovy script at runtime those changes would be honored in XD? (after the 60 second refresh) – Mark Fleischman Aug 12 '15 at 21:01
0

It's not currently possible to re-evaluate the script location at runtime, it's only evaluated at deployment time. You would need to write a custom transform processor.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • Thanks Gary. I am assuming it is just the evaluation piece that is the issue and that SpringXD/groovy-integration would handle any valid groovy file that it found? or is there some other deploy-time dependency that would prevent such an approach? – Mark Fleischman Aug 12 '15 at 21:10
  • It's a bit more involved than that; the underlying Spring Integration XML parser for the `` doesn't support it; it's a fixed resource (loaded into the `RefreshableResourceScriptSource` at initialization time). Re-evaluating it at runtime for each message would require a bunch of infrastructure changes. In the meantime to get it to work, you might have to subclass `GroovyScriptExecutingMessageProcessor` and override the `getScriptSource()` method to return a different `ScriptSource` based on the message. – Gary Russell Aug 12 '15 at 21:32
  • But @David's suggestion is probably easier. – Gary Russell Aug 12 '15 at 21:34
  • Thanks - much appreciated. In my scenario i potentially have a large number of dedicated transformations - so trying to find the best approach to scale this properly. Leveraging the groovy script for it's easy of deployment and versatility seems like a good fit - given that changes are required often in our business. – Mark Fleischman Aug 12 '15 at 22:03