【问题标题】:Spring-Integration: Changing DirectChannel to ExecutorChannel results to ClassCastExceptionSpring-Integration:将 DirectChannel 更改为 ExecutorChannel 结果为 ClassCastException
【发布时间】:2016-09-27 08:38:45
【问题描述】:

我想使用执行器通道而不是直接通道,但我遇到了一个我不明白的问题。

工作配置:

<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]

提前致谢:-)

【问题讨论】:

    标签: spring spring-integration classcastexception channel executor


    【解决方案1】:

    这是一个错误 - 我打开了一个 JIRA Issue。

    作为一种变通方法,您可以将直接频道桥接到执行者频道,或将 newByteArrayChannel 更改为发布订阅频道 - (只有一个订阅者或课程)。

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

    或者您可以将DefaultDatatypeChannelMessageConverter bean 显式注入到通道中。

    【讨论】:

    • 感谢您创建 Jira-Issue 和解决方法,什么工作正常。 :-)
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2014-10-23
      • 1970-01-01
      • 2023-02-06
      • 2016-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多