我有一个具有请求和响应的服务器,它工作正常.现在,我必须为我的应用程序添加一个新的层。
我必须将我的消息放到eh-cache数据库中,然后将ACK发回。目前,我只有一个tcp客户端,但在将来,我将有其他来源,如下所示。

现在的问题是:我可以使用配置这种行为吗?我知道我可以在我的‘importService’上接收消息,并将它放在自己的eh-cache中,以这种方式编写代码:
public MyMessage handler(MyMessage message) {
try {
myCache.put(mykey, message)
} catch (Exception e) {
logger.error("unable to update" + e);
}
return message;
}但是我认为这是不正确的,我只是想知道我是否可以配置我的spring配置文件并添加另一个端点来创建一个链。我当前的配置文件是:
<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示例和连锁示例。谢谢!!
发布于 2014-07-17 15:05:11
好吧,看起来就足以将缓存逻辑转移到ChannelInterceptor了
<int:channel id="tcpInbound">
<int:interceptors>
<bean class="com.my.proj.si.CachePutChannelInterceptor"
</int:interceptors>
</int:channel>当您需要使用Cache时,可以从任何地方使用这个拦截器。
https://stackoverflow.com/questions/24806238
复制相似问题