0

我想用一個執行通道而不是直接的通道,但我面對的一個問題,我不`噸明白。彈簧集成:改變DirectChannel到ExecutorChannel結果ClassCastException異常

工作配置:

<int:channel id="newByteArrayChannel" datatype="java.lang.Byte[]" /> 

<int:service-activator 
    id="myEncryptionServiceActivator" 
    ref="encryptionServiceConnector" 
    method="encrypt" 
    input-channel="newByteArrayChannel" 
    output-channel="encryptedByteArrayChannel" 
    requires-reply="true" 
    send-timeout="1000" 
/> 

更改爲(不工作):

<int:channel id="newByteArrayChannel" datatype="java.lang.Byte[]"> 
    <int:dispatcher task-executor="myExecutor" /> 
</int:channel> 
<task:executor id="myExecutor" pool-size="4" queue-capacity="10" keep-alive="10000"/> 

<int:service-activator 
    id="myEncryptionServiceActivator" 
    ref="myServiceConnector" 
    method="encrypt" 
    input-channel="newByteArrayChannel" 
    output-channel="encryptedByteArrayChannel" 
    requires-reply="true" 
    send-timeout="1000" 
/> 

錯誤:

Exception in thread "main" org.springframework.messaging.MessageDeliveryException: Channel 'newByteArrayChannel' expected one of the following datataypes [class [Ljava.lang.Byte;], but received [class [B] 

謝謝前進:-)

回答

1

這是一個錯誤 - 我打開了JIRA Issue

作爲解決方法,您可以將直接頻道橋接至執行器頻道,或將newByteArrayChannel更改爲發佈訂閱頻道(僅限一個訂閱者或課程)。

<int:publish-subscribe-channel id="newByteArrayChannel" 
     datatype="java.lang.Byte[]" task-executor="myExecutor" /> 

或者您可以明確地將一個DefaultDatatypeChannelMessageConverter bean注入通道。

+0

已添加工作。 –

+0

感謝您爲創建Jira-Issue和解決問題,工作正常。 :-) –

0

以及Gery Russels解決方案的作品,我結束了我也想分享的一個不同的解決方案。我將傳入通道作爲隊列通道,並使用任務執行程序從服務激活器對其進行輪詢:

<int:channel id="newByteArrayChannel" datatype="java.lang.Byte[]"> 
    <int:queue capacity="1000"/> 
</int:channel> 

<int:service-activator 
    id="myEncryptionServiceActivator" 
    ref="myServiceConnector" 
    method="encrypt" 
    input-channel="newByteArrayChannel" 
    output-channel="encryptedByteArrayChannel" 
    requires-reply="true" 
    send-timeout="1000" 
> 
    <int:poller fixed-delay="100" task-executor="myExecutor"/> 
</int:service-activator> 
<task:executor id="myExecutor" pool-size="4-32" queue-capacity="10000" keep-alive="10000"/>