Add adviceChain to StandardIntegrationFlow to set

2019-08-01 23:43发布

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条回答
beautiful°
2楼-- · 2019-08-02 00:19

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) {
查看更多
登录 后发表回答