【问题标题】:How to get Client IP from UDP Transport in Mule ESB?如何从 Mule ESB 中的 UDP 传输获取客户端 IP?
【发布时间】:2016-05-15 13:19:40
【问题描述】:

我正在尝试获取 UDP 包的客户端 IP 和套接字,并使用 MEL 代码将其保存在 Flowvar 变量中

#[message.inboundProperties.MULE_REMOTE_CLIENT_ADDRESS]

但是这个变量总是为空,我已经能够让它在 TCP 传输上工作,有谁知道如何在 UDP 中获取远程客户端地址?

这是我的 XML 文件:

<mule xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata"  xmlns:udp="http://www.mulesoft.org/schema/mule/udp" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="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/udp http://www.mulesoft.org/schema/mule/udp/current/mule-udp.xsd
http://www.mulesoft.org/schema/mule/amqp http://www.mulesoft.org/schema/mule/amqp/current/mule-amqp.xsd">
<udp:connector name="UDP" validateConnections="true" keepSendSocketOpen="true" doc:name="UDP" broadcast="true"/>
<flow name="udpFlow">
<udp:inbound-endpoint exchange-pattern="one-way" host="172.22.20.103" port="4040" connector-ref="UDP" responseTimeout="10000" doc:name="UDP" metadata:id="9260547c-3b58-4ebd-953e-fd3e7bb063f3"/>
<object-to-string-transformer doc:name="Object to String"/>
<set-variable variableName="source" value="#[message.inboundProperties.MULE_REMOTE_CLIENT_ADDRESS]" metadata:id="6a72ad72-167f-44da-9f3d-75143c5c0a2f" doc:name="Variable"/>
<set-payload value="#[flowVars.source] dice #[payload]" doc:name="Set Payload"/>
<echo-component doc:name="Echo"/>
</flow>
</mule>

更新: 我用 MEL 代码解决了地址问题

#[message.inboundProperties['packet.address']]: #[message.inboundProperties['packet.port']]

感谢大卫·多索的帮助。

【问题讨论】:

  • 不用感谢我,我没有意识到 udp 前缀没有附加到 packet.address 属性名称之前,因为它通常是其他其他传输的情况,并且给了你一个错误的名字。你自己解决了:)

标签: udp mule clientip


【解决方案1】:

用途:

#[message.inboundProperties['packet.address']]

【讨论】:

  • 仍然返回 null... 你在哪里找到 'udp.packet.address' 属性?它没有出现在 DataSense Explorer 中
  • 我无法弄清楚 UdpMuleMessageFactory.java 是如何与 'udp.packet.address' 属性相关的,但是如果我尝试使用虚构的属性名称,我会得到相同的 null 结果,所以我猜'udp.packet.address' 不作为属性存在。通过检查 UdpMessageReceiver.java,我意识到属性 MULE_REMOTE_CLIENT_ADDRESS 是在 run() 方法中创建的。这似乎失败了
  • 它通过UdpConnector.ADDRESS_PROPERTY 相关,就在我发送链接的那一行。该代码表明packet.getAddress() 可以是null,因此可能并不总是可以检索此地址。
  • 当前服务器是基于.net的,它接收客户端地址很好,所以包应该没有任何问题,一定是Mule的一些配置错误。客户地址对我们来说是必须的。
猜你喜欢
  • 2011-06-12
  • 2013-10-28
  • 2019-02-16
  • 2018-07-19
  • 2011-12-15
  • 1970-01-01
  • 1970-01-01
  • 2011-08-23
  • 2019-05-08
相关资源
最近更新 更多