繁体   English   中英

如何使用请求路径在Mule ESB中进行路由

[英]How to route in Mule ESB using request path

您好,我正在尝试在流中添加路由器,以便我可以重用我的代码并避免重复。

我通常为每个请求路径执行一个流程,例如:

HTTP LISTENER =本地主机:8080 / mule1 HTTP LISTENER =本地主机:8080 / mule2

我想知道是否可以使用请求路径通过路由器/选择器连接器进行路由。 我无法执行此操作,因为它告诉我/的监听器

这是我的代码:

<flow name="Tickets">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
        <logger message="#[message.inboundProperties.'http.listener.path']" level="INFO" doc:name="Logger"/>
        <choice doc:name="Choice">
            <when expression="#[message.inboundProperties.'http.request.path' == &quot;/getTicketByTicketCode&quot;]">
                <set-payload value="#[message.inboundProperties.'http.query.params'.ticketcode]" doc:name="Set Payload"/>
                <scripting:component doc:name="Groovy">
                    <scripting:script engine="Groovy"><![CDATA[def writer = new StringWriter() 
def xml = new groovy.xml.MarkupBuilder(writer)
xml.mkp.xmlDeclaration(version: "1.0", encoding: "UTF-8")
xml.GetTicketByCode(xmlns: 'http://tempuri.org/') { 
  code(payload)
} 
result = writer.toString() ]]></scripting:script>
                </scripting:component>
                <ws:consumer config-ref="Web_Service_Consumer" operation="GetTicketByCode" doc:name="Web Service Consumer"/>
            </when>
            <when expression="#[message.inboundProperties.'http.request.path' == &quot;/validateTickets&quot;]">
                <scripting:component doc:name="Groovy">
                    <scripting:script engine="Groovy"><![CDATA[]]></scripting:script>
                </scripting:component>
                <ws:consumer config-ref="Web_Service_Consumer" operation="ValidateTicket" doc:name="Web Service Consumer"/>
            </when>
        </choice>
        <mulexml:xslt-transformer xsl-file="removeattributes.xsl" maxIdleTransformers="2" maxActiveTransformers="5" doc:name="XSLT"/>
        <json:xml-to-json-transformer doc:name="XML to JSON"/>
    </flow>


INFO  2015-05-26 09:25:40,303 [[billeterie].HTTP_Listener_Configuration.worker.01] org.mule.module.http.internal.listener.HttpListenerRegistry: No listener found for request: (GET)/getTicketByTicketCode
INFO  2015-05-26 09:25:40,303 [[billeterie].HTTP_Listener_Configuration.worker.01] org.mule.module.http.internal.listener.HttpListenerRegistry: Available listeners are: [(*)/]

有没有办法使这项工作? 或唯一的方法是添加另一个类似于路径的queryParam。 谢谢

您可以使用以下path="/*"并且我已将您的流程修改如下:-

<flow name="Tickets">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/*" doc:name="HTTP"/>
        <logger message="#[message.inboundProperties.'http.listener.path']" level="INFO" doc:name="Logger"/>
        <choice doc:name="Choice">
            <when expression="#[message.inboundProperties.'http.request.path'.contains('/getTicketByTicketCode')]">
                 <logger message="getTicketByTicketCode flow" level="INFO" doc:name="Logger"/>
                 <set-payload value="#[message.inboundProperties.'http.query.params'.ticketcode]" doc:name="Set Payload"/>
                <scripting:component doc:name="Groovy">
                    <scripting:script engine="Groovy"><![CDATA[def writer = new StringWriter() 
def xml = new groovy.xml.MarkupBuilder(writer)
xml.mkp.xmlDeclaration(version: "1.0", encoding: "UTF-8")
xml.GetTicketByCode(xmlns: 'http://tempuri.org/') { 
  code(payload)
} 
result = writer.toString() ]]></scripting:script>
                </scripting:component>
                <ws:consumer config-ref="Web_Service_Consumer" operation="GetTicketByCode" doc:name="Web Service Consumer"/>

            </when>
            <when expression="#[message.inboundProperties.'http.request.path'.contains('/validateTickets')]">
                 <logger message="validateTickets flow" level="INFO" doc:name="Logger"/> 
                  <scripting:component doc:name="Groovy">
                    <scripting:script engine="Groovy"><![CDATA[]]></scripting:script>
                </scripting:component>
                <ws:consumer config-ref="Web_Service_Consumer" operation="ValidateTicket" doc:name="Web Service Consumer"/>
            </when>
            <otherwise>
               <logger message="Other than this url " level="INFO" doc:name="Logger"/> 

            </otherwise>

           <mulexml:xslt-transformer xsl-file="removeattributes.xsl" maxIdleTransformers="2" maxActiveTransformers="5" doc:name="XSLT"/>
        <json:xml-to-json-transformer doc:name="XML to JSON"/> 
        </choice>

    </flow>

现在,如果您的网址包含getTicketByTicketCode,则它将转到第一个流程,如果包含validateTickets,则它将转到第二个流程。...

否则,如果没有这两个中的任何一个,它将在其他情况下打印记录器

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM