簡體   English   中英

Spring集成TCP-> eh-cache鏈

[英]Spring-Integration TCP --> eh-cache chain

我有一個帶有請求和響應的Spring-Integration TCP服務器,它可以正常工作。 好了,現在我必須在應用程序中添加一個新層。

我必須將消息放入eh-cache數據庫,然后發送回ACK。 目前,我只有一個tcp客戶端,但將來,我將有其他來源,如下所示。

在此處輸入圖片說明

現在的問題是:我可以使用Spring-Integration配置此行為嗎? 我知道我可以將消息放在我的'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示例和鏈示例。 謝謝 !!

好吧,看起來足以將您的緩存邏輯移至ChannelInterceptor

<int:channel id="tcpInbound">
   <int:interceptors>
        <bean class="com.my.proj.si.CachePutChannelInterceptor"
   </int:interceptors>
</int:channel>

並在需要使用Cache的任何地方使用此攔截器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM