我在很多情况下都见过 .handle("someBean", "someMethod")
EIP 方法,在集成流程中发挥着巨大的作用。我可以理解它只是以前的 XML 配置中的一个服务激活器,但我需要一些关于如何创建这个 bean 以及 someMethod
返回什么的说明。另外,在什么情况下我必须使用 .handle(...)
?也许使用 Java DSL 的完整示例应该适合我。
最佳答案
正如我们所注意到的,.handle("someBean", "someMethod")
完全等于<int:service-activator ref="someBean" method="someMethod"/>
: https://docs.spring.io/spring-integration/reference/html/messaging-endpoints-chapter.html#service-activator-namespace .
这意味着您应该有 someBean
someMethod
中服务调用的定义。例如,您需要执行简单的逻辑来转换 payload
将传入的消息改为大写并返回结果:
class MyService {
public String someMethod(String payload) {
return payload.toUpperCase();
}
}
该方法的返回结果为 payload
到 IntegrationFlow
中下一个 EIP 端点的出站消息定义。
您在引用手册中看到的所有内容对于 Java DSL 来说都是完全正确的。特别是 <service-activator>
的所有规则或@ServiceActivator
申请此.handle()
.
关于java - Spring Integration Java DSL .handle(String beanName, String methodName),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46470774/