在消息通道之间发送消息时没有发生延迟

时间:2016-05-30 12:58:09

标签: spring spring-integration dsl

我是Spring Integration DSL的新手。目前,我正在尝试添加延迟 消息通道之间 - “ordersChannel”和“bookItemsChannel”。但是,流程继续,好像没有延迟。 任何帮助赞赏。 这是代码:

@Bean
public IntegrationFlow ordersFlow() {
    return IntegrationFlows.from("ordersChannel")
            .split(new AbstractMessageSplitter() {

                @Override
                protected Object splitMessage(Message<?> message) {

                    return ((Order)message.getPayload()).getOrderItems();
                }
            })
            .delay("normalMessage", new Consumer<DelayerEndpointSpec>() {

                public void accept(DelayerEndpointSpec spec) {
                    spec.id("delayChannel");
                    spec.defaultDelay(50000000);
                    System.out.println("Going to delay");
                }
            })
            .channel("bookItemsChannel")
            .get();
}

1 个答案:

答案 0 :(得分:1)

当我看到init和真实运行时,当每个传入消息发生延迟时,似乎混合了System.out.println("Going to delay");阶段。

我们在DSL项目中有一些延迟测试用例,但我只是写了这个以证明defaultDelay运行良好:

@Bean
public IntegrationFlow ordersFlow() {
    return f -> f
            .split()
            .delay("normalMessage", (DelayerEndpointSpec e) -> e.defaultDelay(5000))
            .channel(c -> c.queue("bookItemsChannel"));
}

...

@Autowired
@Qualifier("ordersFlow.input")
private MessageChannel ordersFlowInput;

@Autowired
@Qualifier("bookItemsChannel")
private PollableChannel bookItemsChannel;

@Test
public void ordersDelayTests() {
    this.ordersFlowInput.send(new GenericMessage<>(new String[] {"foo", "bar", "baz"}));

    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    Message<?> receive = this.bookItemsChannel.receive(10000);
    assertNotNull(receive);

    receive = this.bookItemsChannel.receive(10000);
    assertNotNull(receive);

    receive = this.bookItemsChannel.receive(10000);
    assertNotNull(receive);
    stopWatch.stop();

    assertThat(stopWatch.getTotalTimeMillis(), greaterThanOrEqualTo(5000L));
}

如您所见,它与您的配置非常接近,但它并不能证明我们在.delay()周围出了问题。

因此,提供类似的东西以确认意外问题会更好。

相关问题