首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring-Integration TCP -> eh-cache链

Spring-Integration TCP -> eh-cache链
EN

Stack Overflow用户
提问于 2014-07-17 14:25:42
回答 1查看 431关注 0票数 1

我有一个具有请求和响应的服务器,它工作正常.现在,我必须为我的应用程序添加一个新的层。

我必须将我的消息放到eh-cache数据库中,然后将ACK发回。目前,我只有一个tcp客户端,但在将来,我将有其他来源,如下所示。

现在的问题是:我可以使用配置这种行为吗?我知道我可以在我的‘importService’上接收消息,并将它放在自己的eh-cache中,以这种方式编写代码:

代码语言:javascript
复制
public MyMessage handler(MyMessage message) {
        try {
            myCache.put(mykey, message)
            } catch (Exception e) {
            logger.error("unable to update" + e);
            }
        return message;
    }

但是我认为这是不正确的,我只是想知道我是否可以配置我的spring配置文件并添加另一个端点来创建一个链。我当前的配置文件是:

代码语言:javascript
复制
<int-ip:tcp-connection-factory id="serverTcpConFact"  type="server"  port="5566"  using-nio="false"        single-use="false"
  so-receive-buffer-size="8192"
    so-send-buffer-size="8192"
    so-tcp-no-delay="true"
    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="com.MyImportService" />

<int:channel id="tcpOutbound" />

<int-ip:tcp-inbound-gateway id="mygateway"
    request-channel="tcpInbound"
    reply-channel="tcpOutbound"
    reply-timeout="6"/>

<int-ip:tcp-outbound-channel-adapter id="tcpOutboundAdapter"
    channel="tcpOutbound"
    connection-factory="serverTcpConFact" />

我正在查看公共示例,但没有找到eh-cache示例和连锁示例。谢谢!!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-07-17 15:05:11

好吧,看起来就足以将缓存逻辑转移到ChannelInterceptor

代码语言:javascript
复制
<int:channel id="tcpInbound">
   <int:interceptors>
        <bean class="com.my.proj.si.CachePutChannelInterceptor"
   </int:interceptors>
</int:channel>

当您需要使用Cache时,可以从任何地方使用这个拦截器。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24806238

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档