Spring 集成,更改 udp-outbound-channel 端口

Spring Integration, change udp-outbound-channel port

我正在使用 spring 集成在 UDP 中发送文件行。 这是我正在做的事情:

<int-file:inbound-channel-adapter
    prevent-duplicates="false" id="filesIn" directory="file:input"
    channel="inputFiles">
    <int:poller default="true" fixed-rate="1000" />
</int-file:inbound-channel-adapter>

<int:splitter input-channel="inputFiles" output-channel="output">
    <bean class="fr.spring.demo.FileSplitter">
        <property name="commentPrefix" value="#" />
    </bean>
</int:splitter>

<int:transformer input-channel="output" expression="payload"
    output-channel="exampleChannel" />

<int:channel id="exampleChannel" />

<int-ip:udp-outbound-channel-adapter
    id="udpOut" channel="exampleChannel" host="192.168.0.1" port="11111">
</int-ip:udp-outbound-channel-adapter>

因此它从目录中获取文件列表,将文件分成几行并在端口 11111 上发送该行。

我想做的是根据文件的扩展名在预定义的端口上发送行:

谢谢!

目前无法根据消息select端口;欢迎随时开启新功能JIRA Issue.

同时,您可以声明两个适配器,每个端口一个,并添加一个 router 上游以根据文件扩展名路由到一个或另一个。

谢谢加里!

以下是我的处理方式:

<int-file:inbound-channel-adapter
    prevent-duplicates="false" id="filesIn" directory="file:input"
    channel="inputFiles">
    <int:poller default="true" fixed-rate="1000" />
</int-file:inbound-channel-adapter>


<int:chain input-channel="inputFiles">
    <int:header-enricher>
        <int:header name="extension"
            expression="payload.getName().substring(payload.getName().lastIndexOf('.'))" />
    </int:header-enricher>
    <int:splitter>
        <bean class="fr.spring.demo.FileSplitter">
            <property name="commentPrefix" value="#" />
        </bean>
    </int:splitter>
    <int:router expression="headers.extension">
        <int:mapping value=".gps" channel="udpChannel_11111" />
        <int:mapping value=".ths" channel="udpChannel_11112" />
    </int:router>
</int:chain>

<int:channel id="udpChannel_11111" />
<int:channel id="udpChannel_11112" />
<int-ip:udp-outbound-channel-adapter
    channel="udpChannel_11111" host="192.168.0.1" port="11111" />
<int-ip:udp-outbound-channel-adapter
    channel="udpChannel_11112" host="192.168.0.1" port="11112" />