不再有消息

时间:2015-06-01 07:17:59

标签: spring-integration

我正在使用Spring Integration(4.1)配置从数据库中检索作为批处理的消息而不是服务。我知道我每天都会处理十几条消息,因此我需要每天运行一次。

我的jdbc:inbound-channel-adapter配置为检索max-rows-per-poll =“1”。我希望在没有更多消息时以某种方式收到通知,以便我可以退出批处理,但是我有找到“插件”的问题。我尝试使用一个拦截器记住最后一条消息通过+一个计划任务,检索该时间戳并检查它是否超过配置的超时,但感觉非常麻烦并尝试使用AOP,这感觉是一个更好的解决方案。

我想拦截对AbstractPollingEndpoint.doPoll()的调用,当没有消息但我无法找到方法时,我会返回false:我尝试了继承AbstractRequestHandlerAdvice但是在应用时不起作用在轮询器上(它在日志中告诉我)。现在我正在尝试实现MethodInterceptor并配置如下,我看到我可以拦截对“call”方法的调用,但我不确定它是正确的方法

<int:poller default="true" trigger="periodicTriggerWithInitialDelay">
    <int:advice-chain>          
        <bean class="com.myBatch.NoMoreMessageNotifierAdvice" />
        <ref bean="txAdvice"/>
    </int:advice-chain>
</int:poller>

有没有更简单的方法来做到这一点?正如http://forum.spring.io/forum/spring-projects/integration/127410-poller-with-advice-chain所述,主要的困难在于,在这个阶段,我们没有信息可以继续。

由于

文森特

2 个答案:

答案 0 :(得分:0)

看起来我实际上非常接近答案..因为我可以访问调用方法的结果,所以我需要做的就是抛出异常,如果result为false,以及来自问题的XML配置:

public class NoMoreMessageNotifierAdvice实现了MethodInterceptor {

@Override
public Object invoke(MethodInvocation invocation) throws Throwable {

    Object result=invocation.proceed();

    if(result instanceof Boolean){

        boolean hasPolledAMessage=(Boolean)result;

        if(hasPolledAMessage){
            return true;
        }
        else{
            throw new StopBatchException("no message was received on latest poll -> throwing exception to exit");
        }       
    }

    return result;
}

}

答案 1 :(得分:0)

即将发布的4.2版本(我们刚刚发布the first milestone)支持conditional pollers

相关问题