Reputation: 41
I have an application that tries to change the @StreamListener approach to a functional approach, as @StreamListener is deprecated and might be removed someday soon.
The old approach allowed us to use the following conception:
@StreamListener(target = Channel.INPUT_ENROLL, condition = "headers['type']=='Type1'" ...)
handleType1{...}
@StreamListener(target = Channel.INPUT_ENROLL, condition = "headers['type']=='Type2'" ...)
handleType2{...}
...
@StreamListener(target = Channel.INPUT_ENROLL, condition = "headers['type']=='Typen'" ...)
handleTypen{...}
In the project, the routing expression would become something like this, which seems imposible to maintain:
routing-expression: "header['type'] == 'type1' ? 'handleType1' : "header['type'] == 'type2' ? 'handleType2':..."header['type'] == 'typen' ? 'handleTypen' : 'handleUnsupportedType'"
Is there any way other than this to maintain the code?
Upvotes: 1
Views: 229
Reputation: 6106
You can implement MessageRoutingCallback
- https://docs.spring.io/spring-cloud-function/docs/3.2.0-SNAPSHOT/reference/html/spring-cloud-function.html#_function_routing_and_filtering
Upvotes: 1