【问题标题】:Spring Cloud Stream. Sourcing list of events as single events春天云流。将事件列表作为单个事件进行采购
【发布时间】:2018-07-04 13:30:06
【问题描述】:

我使用 Spring Cloud Stream 来获取事件。我的问题是我不想发送到 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;
  }
}

【问题讨论】:

  • 这很好;你为什么质疑它?
  • 是的,但是很麻烦。我认为还有另一种方式,更紧凑。也许用 java dsl?

标签: spring-integration spring-cloud-stream


【解决方案1】:

是的,DSL 会更紧凑

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-05
    • 2011-08-12
    • 2016-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-12
    相关资源
    最近更新 更多