Proxy 通过WSO2 ESB代理在多个系统中搜索用户

Proxy 通过WSO2 ESB代理在多个系统中搜索用户,proxy,wso2,esb,Proxy,Wso2,Esb,我只需要发送一个请求(可以是代理url),该请求将用户id作为输入,并调用多个端点,在聚合所有端点后返回响应 目前,我正在使用代理服务实现来实现它,但is只返回一个响应(可以来自任何端点),无法组合来自其他系统/端点的响应。尽管我可以在服务器控制台中看到来自另一个端点的响应 以下是我迄今为止实现的代码: <?xml version="1.0" encoding="UTF-8"?> <proxy xmlns="http://ws.apache.org/ns/synapse"

我只需要发送一个请求(可以是代理url),该请求将用户id作为输入,并调用多个端点,在聚合所有端点后返回响应

目前,我正在使用代理服务实现来实现它,但is只返回一个响应(可以来自任何端点),无法组合来自其他系统/端点的响应。尽管我可以在服务器控制台中看到来自另一个端点的响应

以下是我迄今为止实现的代码:

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="ProxyTestTwoW"
       transports="http,https"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence>
         <log/>
         <clone>
            <target>
               <sequence>
                  <property name="Application" value="Application1"/>
                  <property name="messageType"
                            value="application/xacml+json"
                            scope="axis2"
                            type="STRING"/>
                  <property name="Authorization"
                            expression="fn:concat('Basic ', base64Encode('username:password'))"
                            scope="transport"/>
                  <send>
                     <endpoint>
                        <address uri="localhost:8080/iiq/rest/identities/9000070"/>
                     </endpoint>
                  </send>
               </sequence>
            </target>
            <target>
               <sequence>
                  <property name="Application" value="Application2"/>
                  <property name="messageType"
                            value="application/xacml+json"
                            scope="axis2"
                            type="STRING"/>
                  <property name="Authorization"
                            expression="fn:concat('Basic ', base64Encode('username:password'))"
                            scope="transport"/>
                  <send>
                     <endpoint>
                        <address uri="http://localhost:8080/iiq/rest/identities/9000071"/>
                     </endpoint>
                  </send>
               </sequence>
            </target>
         </clone>
      </inSequence>
      <outSequence>
         <log level="full" description="">
            <property name="Component" expression="get-property('Application')"/>
         </log>
         <aggregate>
            <completeCondition>
               <messageCount min="2"/>
            </completeCondition>
            <onComplete expression="$body/*[1]">
               <property name="messageType"
                         value="application/xacml+json"
                         scope="axis2"
                         type="STRING"
                         description="messageType"/>
               <send/>
            </onComplete>
         </aggregate>
      </outSequence>
      <faultSequence>
         <log level="full" category="WARN"/>
      </faultSequence>
   </target>
   <description/>
</proxy>
正如我们所看到的,我从服务器日志中的两个端点都得到了响应

根据分析,我觉得要使其正常工作并从两个端点获得响应,我们需要更改以下内容: 1.如果要调用多个端点,则使用调用中介而不是发送。 2.使用enrich mediator存储响应

我尝试了上述方法,但由于我不确定如何在本例中使用enrich mediator,因此无法获得预期的结果

请帮助我解决上述问题。

  • 克隆中介器将用于将消息的相同副本发送到不同的端点
  • 迭代中介器将用于将一条特定消息的消息块发送到不同的端点
  • Enrich mediator将用于更改消息(例如:删除内容、添加内容等)[1]
检查端点,并检查它们是否提供正确的响应以使用聚合中介

我在这里添加了示例场景。您可以使用ESB包对此进行测试,以了解上述三种中介的用法。您只需启动SimpleStockQuote服务[2]的两个实例,并通过SOAPUI将消息发布到代理

<proxy name="ScatterGatherProxy" startOnLoad="true" trace="disable" transports="https http">
    <description/>
    <target>
        <inSequence>
            <clone>
                <target>
                    <sequence>
                        <send>
                            <endpoint name="vendorA">
                                <address uri="http://localhost:9001/services/SimpleStockQuoteService/"/>
                            </endpoint>
                        </send>
                    </sequence>
                </target>
                <target>
                    <sequence>
                        <send>
                            <endpoint name="vendorB">
                                <address uri="http://localhost:9002/services/SimpleStockQuoteService/"/>
                            </endpoint>
                        </send>
                    </sequence>
                </target>
            </clone>
        </inSequence>
        <outSequence>
            <log level="full"/>
            <aggregate>
                <completeCondition>
                    <messageCount min="2"/>
                </completeCondition>
                <onComplete expression="//m0:return"
                    xmlns:m0="http://services.samples" xmlns:m1="http://services.samples/xsd">
                    <enrich>
                        <source clone="true" xpath="//m0:return[not(preceding-sibling::m0:return/m1:last &lt;= m1:last) and not(following-sibling::m0:return/m1:last &lt; m1:last)]"/>
                        <target type="body"/>
                    </enrich>
                    <send/>
                </onComplete>
            </aggregate>
        </outSequence>
    </target>
</proxy>


[2]

您有两个不同的独立问题。理想情况下,您应该将这些问题作为两个问题发布。关于组合响应,迭代器中介器是根据给定信息进行的方式。聚合的方式可能有问题。您是否可以添加来自两个具有完整消息正文等的服务的示例响应作为问题的编辑?请添加两个具有明确详细信息的问题谢谢。我从两个端点都得到响应。但它返回xml数据:schemas.xmlsoap.org/soap/envelope/“>我需要JSON格式的响应。您可以使用XSLT中介。参考示例场景:我尝试使用XSLT,但它不起作用。我仍然得到soap xml格式的响应。我想问题在于xpath表达式中的下面一行:我应该做什么更改来获得响应xml的JSON响应,如下面所示:{“viewableIdentityAttributes”:{“Email”:“Kevin”。Mollo@companyb.com,“cn”:“Kevin Mollo”,“姓氏”:“Mollo”,“名”:“Kevin”},“assignedRoles”:[],“listAttributes”:[“名字”、“姓氏”、“电子邮件”、“cn”]}加上所有JSON响应。
[2016-07-14 11:46:35,057]  INFO - LogMediator To: http://www.w3.org/2005/08/addr
essing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:3beaaf16-7b94-4e
08-a3e0-7605869572c7, Direction: response, Component = Application1, Payload: {"vi
ewableIdentityAttributes":{"Email":"Kevin.Mollo@companyb.com","cn":"Kevin Mollo"
,"Last Name":"Mollo","First Name":"Kevin"},"assignedRoles":[],"listAttributes":[
"First Name","Last Name","Email","cn"]}
[2016-07-14 11:46:35,057]  INFO - LogMediator To: http://www.w3.org/2005/08/addr
essing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:c878c7db-ad4c-49
46-94d6-75aebc75ad8e, Direction: response, Component = Application1, Payload: {"vi
ewableIdentityAttributes":{"Email":"Michelle.Lassauze@companyb.com","cn":"Michel
le Lassauze","Last Name":"Lassauze","First Name":"Michelle"},"assignedRoles":[],
"listAttributes":["First Name","Last Name","Email","cn"]}
<proxy name="ScatterGatherProxy" startOnLoad="true" trace="disable" transports="https http">
    <description/>
    <target>
        <inSequence>
            <clone>
                <target>
                    <sequence>
                        <send>
                            <endpoint name="vendorA">
                                <address uri="http://localhost:9001/services/SimpleStockQuoteService/"/>
                            </endpoint>
                        </send>
                    </sequence>
                </target>
                <target>
                    <sequence>
                        <send>
                            <endpoint name="vendorB">
                                <address uri="http://localhost:9002/services/SimpleStockQuoteService/"/>
                            </endpoint>
                        </send>
                    </sequence>
                </target>
            </clone>
        </inSequence>
        <outSequence>
            <log level="full"/>
            <aggregate>
                <completeCondition>
                    <messageCount min="2"/>
                </completeCondition>
                <onComplete expression="//m0:return"
                    xmlns:m0="http://services.samples" xmlns:m1="http://services.samples/xsd">
                    <enrich>
                        <source clone="true" xpath="//m0:return[not(preceding-sibling::m0:return/m1:last &lt;= m1:last) and not(following-sibling::m0:return/m1:last &lt; m1:last)]"/>
                        <target type="body"/>
                    </enrich>
                    <send/>
                </onComplete>
            </aggregate>
        </outSequence>
    </target>
</proxy>