Splitters

若要创建分隔符,请使用 split() EIP 方法。默认情况下,如果有效负载为 IterableIteratorArrayStream 或反应式 Publisher,则 split() 方法会将各个项输出为单独的消息。它接受 lambda、SpEL 表达式或任何 AbstractMessageSplitter 实现。或者,可以在不使用参数的情况下使用它来提供 DefaultMessageSplitter。以下示例演示了如何通过提供 lambda 来使用 splitWith() 方法:

To create a splitter, use the split() EIP method. By default, if the payload is an Iterable, an Iterator, an Array, a Stream, or a reactive Publisher, the split() method outputs each item as an individual message. It accepts a lambda, a SpEL expression, or any AbstractMessageSplitter implementation. Alternatively, you can use it without parameters to provide the DefaultMessageSplitter. The following example shows how to use the splitWith() method by providing a lambda:

@Bean
public IntegrationFlow splitFlow() {
    return IntegrationFlow.from("splitInput")
              .splitWith(s -> s.applySequence(false).delimiters(","))
              .channel(MessageChannels.executor(taskExecutor()))
              .get();
}

前一个示例创建的分隔符会将包含逗号分隔 String 的消息进行拆分。

The preceding example creates a splitter that splits a message containing a comma-delimited String.

另见 xref:dsl/java-basics.adoc#java-dsl-class-cast[Lambdas And Message<?> 参数。