Search code examples
springspring-cloud-streamspring-cloud-dataflow

Spring Cloud Stream router app


I've been playing with the router sink in the Spring Cloud Stream App Starters, and I have a question about content type.

I'm sending a JSON string to the router, and I would like to write a SpEL expression to determine the routing. However, even when I run this by modifying the JUnit test cases in the project, the "payload" shows up as a string, not parsed JSON. When running JUnit test case for the filter processor, also in the Spring Cloud Stream App Starters, all I need to do is pass valid JSON in a string, and the payload is a LinkedHashMap. (A regular string, like "Hello, world!" makes the payload show up as a String type.)

I really want my router to have a HashMap payload as well. Otherwise, I can't figure out how to write my SpEL expression. I learned earlier how to set a content type on Spring Cloud Stream, and so when I deploy the router in Spring Cloud Dataflow, I try to set it via:

stream deploy --name router-flow --properties "app.router.spring.cloud.stream.bindings.input.content-type=application/json"

However, the payload stills shows up a string. Where am I going wrong?


Solution

  • You can use the #jsonPath() SpEL function - it's automatically registered for use by Stream apps.