WSO2 ESB代理日志介体属性

时间:2016-01-18 02:47:29

标签: wso2 wso2esb esb

我想记录(并且理想地关联)传入和传出消息,并且至少具有以下属性: 约会时间 客户地址(IP,名称可选) 方法

我可以使用以下内容来处理传入消息,但对于传出消息(返回客户端),它将返回null。

get-property('axis2', 'REMOTE_ADDR')

接收

[2016-01-18 13:18:46,339]  INFO - LogMediator To: /services/UserService, WSAction: http://tempuri.org/UserService/Login, SOAPAction: http://tempuri.org/UserService/Login, MessageID: urn:uuid:3e4b7f91-cab0-4294-a013-3c837f6695a0, Direction: request, REMOTE_ADDR: = 172.xx.xx.xx

发送

[2016-01-18 13:18:46,505]  INFO - LogMediator To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:8de88329-3968-4edc-8617-352fbcb5480b, Direction: response, REMOTE_ADDR: = null

当MessageId发生变化时,我也无法将传入和传出的消息关联起来(我猜可以预测)。 是否有必要在入站侧设置自定义属性以将其关联起来?

2 个答案:

答案 0 :(得分:1)

AFAIK,您需要在inSequence上设置自定义属性。 我测试了这个localy,对于下面的代理,我能够获得REMOTE_ADDR:= 172.xx.xx.xx的传入和传出消息。

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="test"
       transports="https,http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence>
         <property name="client-add" expression="get-property('axis2', 'REMOTE_ADDR')"/>
         <log level="custom">
            <property name="REMOTE_ADDR :" expression="get-property('client-add')"/>
         </log>
         <send>
            <endpoint>
               <address uri="http://www.mocky.io/v2/569cac78110000dc24ce7614"/>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <send/>
         <log level="custom">
            <property name="REMOTE_ADDR :" expression="get-property('client-add')"/>
         </log>
      </outSequence>
   </target>
   <description/>
</proxy>

有关在Synapse中序列中重新传输clientIP / Host的更多信息,请参阅此documentation。 有关如何从WSO2弹性负载均衡器的外出请求中获取客户端IP的更多信息,请参阅此documentation

希望这些信息能为您提供帮助。

由于

答案 1 :(得分:0)

是的,您需要向inSequence添加自定义属性介体以获取并保存传入请求的IP地址值。然后通过向inSequence和outSequence添加日志调解器,您将能够看到IP地址也在传出消息中保留。

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="oneProxy"
       transports="https,http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence>
         <property name="ip" expression="get-property('axis2', 'REMOTE_ADDR')"/>
         <log level="full">
            <property name="REMOTE_ADDR :" expression="get-property('ip')"/>
         </log>
         <send>
            <endpoint>
               <address uri="http://localhost:8290/services/echo"/>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <log level="full">
            <property name="REMOTE_ADDR :" expression="get-property('ip')"/>
         </log>
         <send/>
      </outSequence>
   </target>
   <description/>
</proxy>

希望这可以帮助你...

相关问题