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
Well, let's try to investigate!
max-rows-per-poll
is a volatile property of JdbcPollingChannelAdapter
with appropriate setter. JdbcPollingChannelAdapter
does the stuff within its receive()
method just on the initiative of TaskScheduler.schedule()
looks like changing that property at runtime is safe. It is a first point for our taskQueueChannel
has property getQueueSize()
. As far as a capacity
is your configuration option, so you can simply calculate a value for max-rows-per-poll
max-rows-per-poll
just on each poll. So, we should somehow to wedge into poller or polling task. Well, <poller>
has advice-chain
sub-element and we can write some Advice
, which should change JdbcPollingChannelAdapter#setMaxRowsPerPoll
before invoking receive()
and the value should be based on QueueChannel#getQueueSize()
QueueChannel
to the bean of your Advice
And now some bad point: how to inject JdbcPollingChannelAdapter
bean? We provide a hook to register MessageSources
as beans just only since Spring Integration 3.0. From here it's just enough to write this code:
@Autowired @Qualifier("jdbcAdapter.source") private JdbcPollingChannelAdapter messageSource;
We are going to release 3.0.GA this week. So, let me do not consider the reflection 'forest' prior to Sring Integration 3.0. However you can do it using DirectFieldAccessor
on injected SourcePollingChannelAdapter
bean.
UPDATE
Your Advice
may look like this:
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();
}
}
The theory is here: http://docs.spring.io/spring/docs/3.2.5.RELEASE/spring-framework-reference/htmlsingle/#aop