我正在尝试使用选择路由器根据路径处理HTTP消息。这很有效,直到我遇到使用PUT方法提交消息并且路径的尾部是customerID的情况。所以我有一条类似于此的路径:services / v1 / customer / {custNo}。在我选择的路由器中:
<choice doc:name="Route Message By Path">
<when expression="message.inboundProperties['http.relative.path'] == 'services/v1/users'">
<flow-ref name="NewUser" doc:name="New User"/>
</when>
<when expression="message.inboundProperties['http.relative.path'] == 'services/v1/users/{userID}'">
<flow-ref name="UpdateUser" doc:name="Update User"/>
</when>
<when expression="message.inboundProperties['http.relative.path'] == 'services/v1/emails'">
<flow-ref name="CaptureEmail" doc:name="Capture Email"/>
</when>
<when expression="message.inboundProperties['http.relative.path'] == 'services/v1/taxes'">
<flow-ref name="Taxes" doc:name="Taxes"/>
</when>
<otherwise>
<logger message="The path submitted is unknown. Submitted path is: #[message.inboundProperties['http.relative.path']]" level="INFO" doc:name="Unknown path"/>
<set-payload value="The path submitted is unknown. Submitted path is: #[message.inboundProperties['http.relative.path']]" doc:name="Set Payload"/>
<http:response-builder status="500" contentType="text/plain" doc:name="HTTP Response Builder"/>
</otherwise>
</choice>
我使用rest和带注释的java类工作,但是如果可以的话,我宁愿保持简单和mule组件。有没有办法在MEL中为路由器添加通配符?另外,如果继续使用选择路由器,是否有一种从路径中提取客户编号的好/简单方法?
答案 0 :(得分:5)
对于通配符,您可以在MEL表达式中使用正则表达式函数:http://www.mulesoft.org/documentation/display/current/Mule+Expression+Language+Reference 类似的东西:
<when expression="#[regex('services/v1/users/.*', message.inboundProperties['http.relative.path'])]">
但是,我认为apikit和apikit路由器可能更适合您的需求,因为它会自动处理路径和方法路由以及变量模板:http://www.mulesoft.org/documentation/display/current/APIkit+Basic+Anatomy
或者对于旧版本的Mule,可能是Rest路由器:http://mulesoft.github.io/mule-module-rest-router/mule/rest-router-config.html