【发布时间】:2023-11-27 19:51:01
【问题描述】:
骡子 ESB
我正在尝试将 Hello World 程序转换为接受 JSON 对象、检查数据并相应地路由执行的程序。
以下是我的流程的副本:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:json="http://www.mulesoft.org/schema/mule/json" version="EE-3.5.0" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:core="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd">
<json:object-to-json-transformer name="Object_to_JSON" doc:name="Object to JSON"/>
<flow doc:name="HelloWorldFlow1" name="HelloWorldFlow1">
<http:inbound-endpoint doc:description="This endpoint receives an HTTP message." doc:name="HTTP" exchange-pattern="request-response" host="localhost" port="8081" contentType="application/json"/>
<echo-component doc:name="Echo"/>
</flow>
</mule>
我在代码中看到了 object-to-json,我相信它是从 HTTP节点->HTTP设置->内容类型,设置为
application/json
所以我假设传入的对象在流中一次是 JSON 格式,不需要进一步的对象到 JSON 节点。
我将以下字符串发送到流:
{ "uid" : "ABCxxx" }
我想要获得一个节点,该节点将检查并验证 uid 的前三个字母是否为“ABC”,如果是,则将其发送到一条路径,但如果 uid 的前三个字符确实如此不等于“ABC”,走另一条路。有点像一个带有真假配置的IF语句,
以下是伪代码示例
IF uid[3] == "ABC"
GOTO Database Connector
else
GOTO JSON-TO-OBJECT Transformer
我的问题是:我应该使用哪个节点来执行此操作,我应该使用表达式过滤器还是其他
...以及如何在 JSAONPath(或其他)中编写它
(Mule ESB 会执行这种操作吗?)
【问题讨论】:
标签: json conditional mule esb