我想使用执行者频道而不是直接频道,但我遇到了一个我不理解的问题。
工作配置:
<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]
提前致谢: - )
答案 0 :(得分:1)
这是一个错误 - 我打开了JIRA Issue。
作为解决方法,您可以将直接通道桥接到执行程序通道,或将newByteArrayChannel
更改为发布订阅通道 - (只有一个订阅者或课程)。
<int:publish-subscribe-channel id="newByteArrayChannel"
datatype="java.lang.Byte[]" task-executor="myExecutor" />
或者您可以明确地将DefaultDatatypeChannelMessageConverter
bean注入到频道中。
答案 1 :(得分: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"/>