Spring 云流。采购事件列表作为单个事件

Spring Cloud Stream. Sourcing list of events as single events

我使用 spring 云流来采购事件。我的问题是我不想发送到 Source.OUTPUT 事件列表,而是单个事件。配置采购单一事件的最佳做法是什么?我想出了以下解决方案。还有其他方法吗?

@EnableBinding(Source.class)
public class SharedMailboxesPoller {
  @InboundChannelAdapter(channel = "splitterChannel", poller = @Poller(fixedDelay = "30000"))
  public List<NewMailEvent> pollNewMails() {
    ...
    if (!newMailEvents.isEmpty()) {
        return newMailEvents;
    } else {
        //if no events, it will send nothing
        return null;
    }
  }

  @Bean
  public MessageChannel splitterChannel() {
    return MessageChannels.direct().get();
  }

  @Splitter(inputChannel = "splitterChannel", outputChannel = Source.OUTPUT)
  public List<NewMailEvent> newMailEventsSplitter(List<NewMailEvent> newEvents) {
    return newEvents;
  }
}

是的,DSL会更紧凑

IntegrationFlows.from(..., e -> e.poller(...))
                .split()
                .channel(Source.OUTPUT);

或者您可以简单地 return 来自入站适配器的单个事件;只需在 poller 中将 maxMessagesPerPoll 设置为一个大数字,适配器将在每次轮询时被多次调用,直到它 returns null.