Spring integration Spring Integration jdbc:入站通道适配器-将每个轮询的最大行数动态设置为throttle

Spring integration Spring Integration jdbc:入站通道适配器-将每个轮询的最大行数动态设置为throttle,spring-integration,Spring Integration,我有一个JDBC:inbound通道适配器:设置“每次轮询的最大行数”动态以限制通道上传递的消息 我有一个队列通道,容量为200。入站通道适配器将向该队列通道发送消息。我想根据QueueChannel的剩余容量设置“每轮询最大行数”值 为此,我尝试将QueueChannel注入Bean中,但在部署war文件时出错 错误:由于StateConversionError,无法注入QueueChannel 我有没有其他方法可以做到这一点 更新:我正在使用Spring-Integration-2.2.0.

我有一个JDBC:inbound通道适配器:设置“每次轮询的最大行数”动态以限制通道上传递的消息

我有一个队列通道,容量为200。入站通道适配器将向该队列通道发送消息。我想根据QueueChannel的剩余容量设置“每轮询最大行数”值

为此,我尝试将QueueChannel注入Bean中,但在部署war文件时出错

错误:由于StateConversionError,无法注入QueueChannel

我有没有其他方法可以做到这一点

更新:我正在使用Spring-Integration-2.2.0.RC2

这是jdbc入站适配器的配置:

<si-jdbc:inbound-channel-adapter id ="jdbcInboundAdapter" channel="queueChannel" data-source="myDataSource" auto-startup="true" query="${select.query}"
update="${update.query}" max-rows-per-poll="100"  row-mapper="rowMapper" update-per-row="true">
 <si:poller fixed-rate="5000">
    <si:transactional/>
     <si:advice-chain>
           <bean class="foo.bar.InboundAdapterPollingConfigurationImpl"/>
     </si:advice-chain>
  </si:poller>
</si-jdbc:inbound-channel-adapter>
问题是如何从通知链调用InboundAdapterPollingConfigurationMPL.setJdbcInboundAdapterMaxRowsPerPoll方法。很抱歉这个天真的问题,但这是我第一次使用建议链。我也在寻找一个例子,但还不走运

更新2: 执行此操作时出现以下错误:

JdbcPollingChannelAdapter source = (JdbcPollingChannelAdapter)dfa.getPropertyValue("source"); 
错误:

 java.lang.ClassCastException: $Proxy547 cannot be cast to org.springframework.integration.jdbc.JdbcPollingChannelAdapter – 

我有JDK1.6_26。我在一篇帖子中读到,JDK1.6的早期版本中发生了这种情况。

好吧,让我们试着调查一下

每次轮询的最大行数是具有适当setter的JdbcPollingChannelAdapter的易失性属性。 就JdbcPollingChannelAdapter而言,只是在TaskScheduler.schedule的倡议下在其receive方法中执行这些操作,看起来在运行时更改该属性是安全的。这是我们任务的第一点 QueueChannel具有属性getQueueSize。由于容量是您的配置选项,因此您可以简单地计算每次轮询的最大行数 现在如何让它工作呢?实际上,您感兴趣的是每次轮询的最大行数。所以,我们应该设法插入轮询器或轮询任务。嗯,有advice chain子元素,我们可以编写一些advice,它应该在调用receive之前更改JdbcPollingChannelAdaptersetMaxRowsPerPoll,并且该值应该基于QueueChannelgetQueueSize 将您的QueueChannel注入您的建议bean 现在有一些缺点:如何注入jdbcpollingchanneladapterbean?仅从SpringIntegration3.0开始,我们就提供了一个将MessageSources注册为bean的钩子。从这里开始,只需编写以下代码即可:

@自动连线 @限定符JDBCAdapter.source 私有JdbcPollingChannelAdapter消息源

本周我们将发布3.0.GA。因此,让我不考虑反射“森林”之前的SLink集成3。但是,您可以在注入的SourcePollingChannelAdapter bean上使用DirectFieldAccessor来实现

更新

您的建议可能如下:

public class MyAdvice implements MethodInterceptor {
       @Autowired
       QueueChannel queueChannel;

       @Autowired
       SourcePollingChannelAdapter jdbcInboundAdapter; 

      Object invoke(MethodInvocation invocation) throws Throwable {
            DirectFieldAccessor dfa = new DirectFieldAccessor(jdbcInboundAdapter);
            JdbcPollingChannelAdapter source = (JdbcPollingChannelAdapter) dfa.getPropertyValue("source");
            source.setMaxRowsPerPoll(queueChannel.getRemainingCapacity());
            return invocation.proceed();
      }
}

理论就在这里:

我正在努力实现它。一个简单的问题:您将如何从被引用bean的建议链中调用特定方法。不确定您的意思。你能展示一个案例,或者用其他的话来表达吗。ThanksI为您添加了一个实现。干杯执行此操作时出现此错误:JdbcPollingChannelAdapter source=JdbcPollingChannelAdapter dfa.getPropertyValuesource;:java.lang.ClassCastException:$Proxy547不能强制转换为org.springframework.integration.jdbc.jdbcpollingchanneladapter首先您应该在中配置。不清楚为什么是“$Proxy547”。我在当地做了测试,一切正常。您是否有特定的全局AOP配置?例如JMX?尝试找到谁将JdbcPollingChannelAdapter`打包到代理
public class MyAdvice implements MethodInterceptor {
       @Autowired
       QueueChannel queueChannel;

       @Autowired
       SourcePollingChannelAdapter jdbcInboundAdapter; 

      Object invoke(MethodInvocation invocation) throws Throwable {
            DirectFieldAccessor dfa = new DirectFieldAccessor(jdbcInboundAdapter);
            JdbcPollingChannelAdapter source = (JdbcPollingChannelAdapter) dfa.getPropertyValue("source");
            source.setMaxRowsPerPoll(queueChannel.getRemainingCapacity());
            return invocation.proceed();
      }
}