如何决定首先调用哪个频道?

时间:2016-10-14 07:13:26

标签: spring-integration

我有一个代码

<int-jpa:inbound-channel-adapter channel="transactionChannel" 
entity-manager="entityManager" 
jpa-query="select t from Transaction t ,QueueConfiguration q where    t.transactionStatus='RDY2BATCH' and t.partner.partnerId=q.partnerId" 
expect-single-result="false">
<int:poller default="true" fixed-delay="150000" />
</int-jpa:inbound-channel-adapter>

<int-jpa:inbound-channel-adapter id="configurationReader"
		channel="configurationChannel" entity-manager="entityManager"
		jpa-query="select s from Setting s where s.SettingsCategory.categoryId='1'"
		expect-single-result="false">
</int-jpa:inbound-channel-adapter>

从这里我的项目开始,这里我有2个通道,我希望配置只在项目启动时执行一次,因为它有静态值,我需要从DB读取,我将在我的项目中使用它。如何在项目开始时第一次调用?

1 个答案:

答案 0 :(得分:1)

为此,我们建议使用Only Once Trigger解决方案:

public class OnlyOnceTrigger implements Trigger {

    private final AtomicBoolean done = new AtomicBoolean();

    @Override
    public Date nextExecutionTime(TriggerContext triggerContext) {
        return !done.getAndSet(true) ? new Date() : null;
    }

}

此外,您可以考虑对ContextRefreshedEvent作出反应,并使用<int-jpa:retrieving-outbound-gateway>执行相同的JPAQL。