Spring Integration Splitter之后丢失的消息。数据未随机到达聚合器

时间:2016-07-18 19:22:19

标签: spring-integration splitter aggregator

我正在尝试并行处理SQL查询的输出。下面给出的是我的代码。我在Aggregator中有sysout。但我随机看到聚合器中的sysout没有被打印出来。此外,聚合器中的释放方法也不是打印sysouts。我想,我正在失去一些消息。任何一个人都可以解雇一些吗?

    <int:bridge input-channel="inputChannel" output-channel="dbRequestChannel" />

        <jdbc:outbound-gateway request-channel="dbRequestChannel"
            max-rows-per-poll="0" data-source="dataSource" reply-channel="headerEnricher"
            query="select empname, empno, empdob from employee where empno = 1234" />

        <int:header-enricher input-channel="headerEnricher"
            output-channel="splitterChannel">
            <int:header name="payloadSize" value="3"></int:header>
        </int:header-enricher>

        <int:chain input-channel="splitterChannel" output-channel="splitterOutputChannel">
            <int:splitter />
        </int:chain>


        <int:channel id="splitterOutputChannel">
            <int:dispatcher task-executor="sampleTaskExecutor" />
        </int:channel>

        <bean id="sampleTaskExecutor"
            class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
            <property name="corePoolSize" value="5" />
            <property name="maxPoolSize" value="10" />
            <property name="queueCapacity" value="25" />
        </bean>

        <int:service-activator input-channel="splitterOutputChannel"
            ref="springIntegrationtest" method="testMethod" output-channel="aggregatePayload">
        </int:service-activator>

        <int:aggregator input-channel="aggregatePayload"
            release-strategy-method="release" output-channel="nullChannel"
            send-partial-result-on-expiry="true" ref="springIntegrationtest"
            method="aggregateData" />

    @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:spring-integration.xml" })
public class SpringIntegrationTest {


    @Autowired
    private MessageChannel inputChannel;

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");



    @Test
    public void testQueue() {
        Message<String> quoteMessage = MessageBuilder
                .withPayload("testPayload").build();
        inputChannel.send(quoteMessage);
    }


    public Map<String, String> testMethod(Message<?> m) {

        System.out.println(sdf.format(new Date()));
        return (Map<String, String>) m.getPayload();
    }

    public boolean release(ArrayList<Map<String, Object>> payload) {
        boolean release = false;
        int size = payload.size();
        if (size == 3) {
            release = true;
        }
        System.out.println(release);
        return release;
    }

    public Message<String> aggregateData(ArrayList<Map<String, Object>> payload) {

        System.out.println("In aggregateData " + payload);
        Message<String> quoteMessage = MessageBuilder
                .withPayload("testPayload").build();
        return quoteMessage;
    }

}

1 个答案:

答案 0 :(得分:1)

嗯,我认为你的问题在于状态和选项的组合。

你有这个:

int size = payload.size();
if (size == 3) {
    release = true;
}

因此,您的聚合器将在3项到达后立即释放该组,同时您可能在拆分后拥有更多项目。

release信号聚合器完成组并退出。默认情况下,它有expireGroupsUponCompletion = false之类的选项,这意味着保留组在商店中但具有completed状态。

如果你的目标只是从聚合器元组发出3,你应该考虑将expireGroupsUponCompletion切换到true。有关详细信息,请参阅聚合器manual