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"/>