I have a JDBC:inbound-channel-adapter : To set the 'max-rows-per-poll' dynamic to throttle the messages getting passed on the channel.
I have a QueueChannel which has a capacity of 200. The inbound-channel-adapter would be sending the message to this QueueChannel. I would like to set the 'max-rows-per-poll' value depending on the RemainingCapacity of the QueueChannel.
For this I tried to Inject the QueueChannel in a Bean but I get the error when deploying the war file.
Error: Cannot Inject the QueueChannel due to StateConversionError.
Is there any other way I could achieve this.
Update : I am using Spring-Integration-2.2.0.RC2
This is the config for 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>
Bean:
@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);
}
}
The question is how to call the InboundAdapterPollingConfigurationImpl.setJdbcInboundAdapterMaxRowsPerPoll() method from the advice chain. Sorry for the naive question but t is my first time using the advice-chain. Also I am searching for an example but was not lucky yet.
Update2: Got the below error when this is executed:
JdbcPollingChannelAdapter source = (JdbcPollingChannelAdapter)dfa.getPropertyValue("source");
Error:
java.lang.ClassCastException: $Proxy547 cannot be cast to org.springframework.integration.jdbc.JdbcPollingChannelAdapter –
I have the JDK1.6_26. I read in one of the posts that this is happening in the early versions of JDK1.6.