Transformers
DSL API 提供了一个方便、流畅的 Transformers
工厂,供用作 .
内联目标对象定义的 transform()
EIP 方法。以下示例展示了如何使用它:
The DSL API provides a convenient, fluent Transformers
factory to be used as inline target object definition within the .transform()
EIP method.
The following example shows how to use it:
@Bean
public IntegrationFlow transformFlow() {
return IntegrationFlow.from("input")
.transform(Transformers.fromJson(MyPojo.class))
.transform(Transformers.serializer())
.get();
}
它避免了使用 setter 的繁琐编码,并使流定义更简单。请注意,你可以使用 Transformers
将目标 Transformer
实例声明为 @Bean
实例,然后再次从 IntegrationFlow
定义中使用它们作为 bean 方法。尽管如此,如果 DSL 解析器尚未将内联对象定义为 bean,它会负责 bean 声明。
It avoids inconvenient coding using setters and makes the flow definition more straightforward.
Note that you can use Transformers
to declare target Transformer
instances as @Bean
instances and, again, use them from IntegrationFlow
definition as bean methods.
Nevertheless, the DSL parser takes care of bean declarations for inline objects, if they are not yet defined as beans.
有关更多信息和支持的工厂方法,请参见 Javadoc 中的 Transformers。
See Transformers in the Javadoc for more information and supported factory methods.
从 6.2 版本开始,引入了 transformWith(Consumer<TransformerEndpointSpec>)
变体,以便通过单个构建器参数配置所有变换器及其端点选项。这种样式为 DSL 提供了更好的可读性,并在修改代码时提升了开发者体验。这也使 Groovy 和 Kotlin DSL 更直接。
Starting with version 6.2, a transformWith(Consumer<TransformerEndpointSpec>)
variant has been introduced to have all the transformer and its endpoint options to be configured via single builder argument.
This style gives DSL more readability and increases developer experience while modifying code.
This also make Groovy and Kotlin DSLs more straightforward.
另见 xref:dsl/java-basics.adoc#java-dsl-class-cast[Lambdas And Message<?>
参数。
Also see Lambdas And Message<?>
Arguments.