That's correct. A message with null
payload
does not make sense for messaging system, like Spring Integration. Actually no one existing messaging protocol support null
payload.
Hence it is standard behavior for many result-aware
adapter to do nothing, when there is no data from the underlying system, like JDBC in your case.
The code looks like:
private Object poll() {
List<?> payload = doPoll(this.sqlQueryParameterSource);
if (payload.size() < 1) {
payload = null;
}
if (payload != null && updateSql != null) {
if (this.updatePerRow) {
for (Object row : payload) {
executeUpdateQuery(row);
}
}
else {
executeUpdateQuery(payload);
}
}
return payload;
}
As you see an update
isn't reachable when ResultSet
is empty.
There is a hook for you to achieve your requirements. The <poller>
can be configured with <advice-chain>
, where and Advice is applied for the Callable<Boolean>.call()
method in the AbstractPollingEndpoint
. in that custom MethodInterceptor
you can check the result of invocation.proceed()
, which is true
if the underlying MessageSource
(JdbcPollingChannelAdapter
in our case) returns a data or not.
With the false
result you really can do that required UPDATE
in that auxiliary database.
We have a open issue, by the way, to support null
payloads. I have an idea for the solution to use Java 8's Optional<?>
, which can be trasparently converted to target object for nay downstream POJO service-activator, transformer, splitter etc.
Feel free to add any comments there!
UPDATE
How implement this class com.service.ValidateResultAdvice ?
public class ValidateResultAdvice implements MethodInterceptor {
private JdbcTemplate jdbcTemplate;
public Object invoke(MethodInvocation invocation) throws Throwable {
Boolean result = (Boolean) invocation.proceed();
if (!result) {
this.jdbcTemplate.update(...);
}
return result;
}
}
Something like that.