【问题标题】:Spring integration send ack using gatewaySpring集成使用网关发送ack
【发布时间】:2014-07-04 13:10:19
【问题描述】:

我有一个生产者(用 CPP 编写)将二进制数据发送到“spring-integration server”。 它可以正常工作: spring integration time out clients

现在我必须向生产者发送回复(如 ACK)。

我已经阅读过有关网关的信息,但实际上我很困惑。 我的配置是:

<int-ip:tcp-connection-factory id="serverTcpConFact"
    type="server"
    port="5566"
    using-nio="true"
    single-use="false"

    task-executor="myTaskExecutor"
    deserializer="serializer" 
    serializer="serializer"/>

<int-ip:tcp-inbound-channel-adapter id="tcpInboundAdapter"
    channel="tcpInbound"
    connection-factory="serverTcpConFact" />

<int:channel id="tcpInbound" />


<int:service-activator 
    output-channel="tcpOutbound" 
    input-channel="tcpInbound"
    ref="importService"
    method="handler" />

<bean id="importService" class="my.ImportService" />

<int:channel id="tcpOutbound" />

<int:gateway id="mygateway"
    service-interface="my.IpMyGatway"
    default-request-channel="tcpInbound"
    default-reply-channel="tcpOutbound"
    default-reply-timeout="6000"/>

我还有一个自定义序列化器,问题是我的 spring 集成服务器没有发送回复。

我需要回复执行:

@Override
    public void serialize(MyMessage arg0, OutputStream outputStream) throws IOException {
        // TODO Auto-generated method stub
         logger.info("serialize messages");
// here I have to write my ACK ! ( .. or not?)
    }

然后将消息发送给每个消息的生产者。

谢谢。

【问题讨论】:

    标签: java spring spring-integration


    【解决方案1】:

    我想知道为什么 &lt;int-ip:tcp-inbound-gateway&gt; 对你来说还不够...

    足以从service 生成回复消息,网关会将其作为响应发送给客户端。

    简单示例:

    <ip:tcp-inbound-gateway id="gatewaySerializedNio"
            connection-factory="connectionFactory"
            request-channel="serviceChannel" />
    
    <channel id="serviceChannel" />
    
    <service-activator input-channel="serviceChannel"
            ref="service" method="process"/>
    
    <beans:bean id="service" class="com.my.proj.MyService" />
    

    MyService#process 方法的返回值将被序列化到 TCP 套接字。

    【讨论】:

    • 谢谢@Artem Bilan,但我不明白你对reply message 意味着什么。你能不能更好地解释一下?
    • 在答案中添加了示例
    猜你喜欢
    • 2019-07-12
    • 2014-10-28
    • 1970-01-01
    • 1970-01-01
    • 2012-05-21
    • 2018-06-15
    • 2014-07-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多