我根据有效载荷选择路线。有效负载可以是列表,映射或字符串。必须根据有效载荷类型识别和路由有效载荷。
答案 0 :(得分:6)
我认为你想要那样的东西
<choice doc:name="Choice">
<when expression="#[payload is List]">
<logger level="INFO" message="i am list" doc:name="Logger"/>
</when>
<when expression="#[payload is Map]">
<logger level="INFO" message="i am map" doc:name="Logger"/>
</when>
<when expression="#[payload is String]">
<logger level="INFO" message="i am string" doc:name="Logger"/>
</when>
<otherwise>
<logger message="class doesnt match with [list, map, string]" level="INFO" doc:name="Logger"/>
</otherwise>
</choice>
答案 1 :(得分:4)
我同意Eddú的回复,除了我会添加otherwise
路径。如果你不这样做并得到一些不同于列表地图或字符串的东西,你会得到相当神秘的错误:
org.mule.api.routing.RoutePathNotFoundException: Can't process message because no route has been found matching any filter and no default route is defined. Failed to route event via endpoint: ChoiceRouter [flow-construct=testNull, started=true]. Message payload is of type: NullPayload