Add adviceChain to StandardIntegrationFlow to set a CountDownLatch on a message handler

六眼飞鱼酱① 提交于 2019-12-13 19:12:07

问题


I´m trying to add a CountDownLatch to an org.springframework.integration.dsl.StandardIntegrationFlow in Spring Integration via an adviceChain and the BeanFactoryPostProcessor. The reason for this is to monitor, if the message handler within this integration flow was called and has finished his work or not.

There is a solution without using the Java DSL of Spring Integration here: spring-integration unit test outbound-channel adapter. But sadly it´s not working for me because of the Java DSL and the StandardIntegrationFlow. Gary Russels solution looks like this: https://gist.github.com/garyrussell/5481779. My exception trying this is:

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?

The integration flow looks like this:

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

I need to add a CountDownLatch to the .handle() part, thus enabling me to ask the latch if the handler has finished its work.

Any ideas how to achieve this?


回答1:


The IntegrationFlow essentially does nothing with integration at all. It is a logical container for real Spring Integration endpoints and message channels between them. So, if you are talking about the advice exactly for the .handle(), what is really correct, you should consider to do this:

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

Where that advice() is about:

/**
 * 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) {


来源:https://stackoverflow.com/questions/46409149/add-advicechain-to-standardintegrationflow-to-set-a-countdownlatch-on-a-message

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!