0

I've implemented an advice handler attached to outbound-gateway components in order to be able to long outgoing HTTP requests before/after. Originally, this was for a Spring-Integration project using MVC/servlet underpinnings. (Original question: Logging http request in Spring integration http outbound gateway )

We are attempting a migration to webflux/reactive which means that we are using a webflux:outbound-gateway in lieu of a http:outbound-gateway.

The advice handler is an around call in the doInvoke() method:


public class MyLogger extends AbstractRequestHandlerAdvice {

   // ...

   @Override
   protected Object doInvoke(ExecutionCallback callback, Object target, Message<?> message( 
   {

      // ... logging before the call ...

      Object result = callback.execute();

      // ... logging after the call ...

      return result;
   }

}

Whereas I understand that the webflux:outbound-gateway call itself is supposed to be asynchronous (i.e. no threads waiting on a response), it would seem to me that the advice handler itself must be implemented synchronously (i.e. thread awaiting the response). Am I understanding correctly? Is the advice handler adding synchronicity that wouldn't otherwise be there?

Thanks for any insights on this point.

al.truisme
  • 450
  • 2
  • 11
  • 1
    It won't block, but it won't do what you want; the result will be a `Mono`, which will be completed later. – Gary Russell Nov 22 '22 at 18:42
  • OK, I see. I guess that I'll be looking for an equivalent to advice handling for logging outbound http responses. Thanks. – al.truisme Nov 22 '22 at 20:09
  • OK, I see, using ```share()``` as you mentioned in the sister post. Thanks. https://stackoverflow.com/questions/74537523/spring-integration-how-to-inspect-a-http-response-within-an-abstractrequesthand/74537804#74537804 – al.truisme Nov 22 '22 at 20:10

1 Answers1

1

There is a ReactiveRequestHandlerAdvice for this particular use-case to wrap a reply Mono with anything you'd like: https://docs.spring.io/spring-integration/docs/current/reference/html/messaging-endpoints.html#reactive-advice

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118