将adviceChain添加到StandardIntegrationFlow以在消息处理程序

时间:2017-09-25 15:42:38

标签: spring unit-testing spring-integration spring-integration-dsl

我尝试通过CountDownLatchorg.springframework.integration.dsl.StandardIntegrationFlow向Spring Integration中的adviceChain添加BeanFactoryPostProcessor。这样做的原因是监视,如果调用此集成流程中的消息处理程序并且是否已完成其工作。

有一种解决方案,不使用Spring Integration的Java DSL:spring-integration unit test outbound-channel adapter。但遗憾的是,由于Java DSL和StandardIntegrationFlow,它不适合我。 Gary Russels解决方案如下所示:https://gist.github.com/garyrussell/5481779。我尝试这个的例外是:

Caused by: org.springframework.beans.NotWritablePropertyException: 
Invalid property 'adviceChain' of bean class [org.springframework.integration.dsl.StandardIntegrationFlow]: 
Bean property 'adviceChain' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

整合流程如下所示:

@Bean
public IntegrationFlow myFlow() {
    return IntegrationFlows.from(myChannel())
            .handle(message -> manager.handleMessage(message))
            .get();
}

我需要在CountDownLatch部分添加.handle(),这样我就可以在处理程序完成其工作时询问锁存器。

任何想法如何实现这一目标?

1 个答案:

答案 0 :(得分:1)

IntegrationFlow基本上对整合没有任何作用。它是真正的Spring Integration端点和它们之间的消息通道的逻辑容器。所以,如果你正在讨论.handle()的建议,那么真正正确的是,你应该考虑这样做:

.handle(message -> manager.handleMessage(message), e -> e.advice(...))

advice()的含义:

/**
 * Configure a list of {@link Advice} objects to be applied, in nested order, to the
 * endpoint's handler. The advice objects are applied only to the handler.
 * @param advice the advice chain.
 * @return the endpoint spec.
 */
public S advice(Advice... advice) {