【发布时间】:2013-12-10 17:25:02
【问题描述】:
我有一个 JDBC:inbound-channel-adapter :设置 'max-rows-per-poll' 动态以限制在通道上传递的消息。
我有一个容量为 200 的 QueueChannel。入站通道适配器会将消息发送到此 QueueChannel。我想根据 QueueChannel 的 RemainingCapacity 设置 'max-rows-per-poll' 值。
为此,我尝试在 Bean 中注入 QueueChannel,但在部署 war 文件时出现错误。
错误:由于 StateConversionError 无法注入 QueueChannel。
有没有其他方法可以实现这一点。
更新:我正在使用 Spring-Integration-2.2.0.RC2
这是 jdbc-inbound-adapter 的配置:
<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>
豆子:
@Service
public class InboundAdapterPollingConfigurationImpl implements InboundAdapterPollingConfiguration{
private static final Logger logger = LoggerFactory.getLogger(InboundAdapterPollingConfigurationImpl.class);
@Autowired
QueueChannel queueChannel;
@Autowired
SourcePollingChannelAdapter jdbcInboundAdapter;
public void setJdbcInboundAdapterMaxRowsPerPoll(){
String size = String.valueOf(queueChannel.getRemainingCapacity());
DirectFieldAccessor directFieldAccessor = new DirectFieldAccessor(jdbcInboundAdapter);
directFieldAccessor.setPropertyValue("setMaxRowsPerPoll", size);
String maxRowsPerPollSize = (String)directFieldAccessor.getPropertyValue("setMaxRowsPerPoll");
System.out.println(maxRowsPerPollSize);
}
}
问题是如何从建议链中调用 InboundAdapterPollingConfigurationImpl.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 的早期版本中。
【问题讨论】: