According to spring-cloud-stream reference,
we can customize content-type of send message with setting MessageHeaders.CONTENT_TYPE, but when property has no spring.cloud.stream.rabbit.bindings.[channel name].producer.routing-key-expression, the message is transformed by the Cloud Function using the content type specified in the expected-conten-type header.
`org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry. FunctionInvocationWrapper#convertOutputMessageIfNecessary.
If you specify the routing-key-expression property in the binding (channel), the conversion in the Cloud Function will be skipped and the message will be converted in the Cloud Stream. This was fixed in the #2145 issue to evaluate SpEL for routing-key-expression.
However, if you define multiple output bindings and mix the presence or absence of routing-key-expression settings, an error will occur.
The minimum reproducible sample (application.yml) is shown below.
spring:
cloud:
function:
definition: msgHandlerA;msgHandlerB
stream:
bindings:
msgHandlerA-out-0:
destination: regularOrder
msgHandlerB-out-0:
destination: order
rabbit:
bindings:
msgHandlerA-out-0:
producer:
routing-key-expression: payload.foo
In this case, it is determined that the routing-key-expression is not set in binding msgHandlerB-out-0, so it is not skipped in the Cloud Function, but this decision will also affect binding msgHandlerA-out-0.
As a result, binding msgHandlerA-out-0 is transformed in the Cloud Function, which results in an error when evaluating the routing-key-expression.
Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'foo' cannot be found on object of type 'byte[]' - maybe not public or not valid?
at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:217)
The decision should be made on each binding (channel) basis to skip conversions in Cloud Functions.
This error has been confirmed for SpringBoot 2.7.6(spring-cloud-stream 3.2.6) and 3.1.1(spring-cloud-stream 4.0.3).
According to spring-cloud-stream reference,
we can customize content-type of send message with setting
MessageHeaders.CONTENT_TYPE, but when property has nospring.cloud.stream.rabbit.bindings.[channel name].producer.routing-key-expression, the message is transformed by the Cloud Function using the content type specified in theexpected-conten-typeheader.`org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry. FunctionInvocationWrapper#convertOutputMessageIfNecessary.
If you specify the
routing-key-expressionproperty in the binding (channel), the conversion in the Cloud Function will be skipped and the message will be converted in the Cloud Stream. This was fixed in the #2145 issue to evaluate SpEL forrouting-key-expression.However, if you define multiple output bindings and mix the presence or absence of
routing-key-expressionsettings, an error will occur.The minimum reproducible sample (application.yml) is shown below.
In this case, it is determined that the
routing-key-expressionis not set in bindingmsgHandlerB-out-0, so it is not skipped in the Cloud Function, but this decision will also affect bindingmsgHandlerA-out-0.As a result, binding
msgHandlerA-out-0is transformed in the Cloud Function, which results in an error when evaluating therouting-key-expression.The decision should be made on each binding (channel) basis to skip conversions in Cloud Functions.
This error has been confirmed for SpringBoot 2.7.6(spring-cloud-stream 3.2.6) and 3.1.1(spring-cloud-stream 4.0.3).