Spring-集成:将 DirectChannel 更改为 ExecutorChannel 结果为 ClassCastException
Spring-Integration: Changing DirectChannel to ExecutorChannel results to 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]
提前致谢:-)
这是一个错误 - 我打开了 JIRA Issue。
作为变通方法,您可以将直接通道桥接到执行程序通道,或将 newByteArrayChannel
更改为发布订阅通道 -(只有一个订阅者或课程)。
<int:publish-subscribe-channel id="newByteArrayChannel"
datatype="java.lang.Byte[]" task-executor="myExecutor" />
或者您可以显式地将 DefaultDatatypeChannelMessageConverter
bean 注入通道。
尽管 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"/>
我想使用执行器通道而不是直接通道,但我遇到了一个我不明白的问题。
工作配置:
<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]
提前致谢:-)
这是一个错误 - 我打开了 JIRA Issue。
作为变通方法,您可以将直接通道桥接到执行程序通道,或将 newByteArrayChannel
更改为发布订阅通道 -(只有一个订阅者或课程)。
<int:publish-subscribe-channel id="newByteArrayChannel"
datatype="java.lang.Byte[]" task-executor="myExecutor" />
或者您可以显式地将 DefaultDatatypeChannelMessageConverter
bean 注入通道。
尽管 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"/>