【发布时间】:2023-03-19 09:07:01
【问题描述】:
我有一个使用函数式方法的 Spring Cloud Stream 应用程序。该应用程序使用 一个路由表达式,用于将消息过滤到检查负载的消费者函数。
spring:
cloud:
function:
routing-expression: "payload['type'] == 'Event' ? 'handleEvent' : 'commitIgnoredEvent'"
definition: functionRouter;handleDlqMessage
这个配置给出了例外:
org.springframework.messaging.MessageHandlingException: error occurred
in message handler [org.springframework.cloud.stream.
function.FunctionConfiguration$FunctionToDestinationBinder$1@3aff91a]; nested exception is
org.springframework.expression.spel.SpelEvaluationException:
EL1027E: Indexing into type 'org.apache.avro.generic.GenericData$Record'
is not supported, failedMessage=GenericMessage
但是,这个使用标头的配置将不会抛出异常:
spring:
cloud:
function:
routing-expression: "header['type'] == 'Event' ? 'handleEvent' : 'commitIgnoredEvent'"
definition: functionRouter;handleDlqMessage
生产系统不使用标题,所以我不能使用第二个选项。路由表达式是否仅适用于标头?是否缺少启用有效负载检查的配置?
【问题讨论】:
-
您似乎正在尝试将其作为地图进行访问。试试
payload.type(如果有getType()方法)。 -
感谢加里的工作!如果您将评论转换为答案,我可以接受。
标签: java spring apache-kafka spring-kafka spring-cloud-stream