You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* GH-3183: Add ReactiveRequestHandlerAdvice
Fixes#3183
* Introduce a `ReactiveRequestHandlerAdvice` with a `BiFunction<Message<?>, Mono<?>, Publisher<?>>`
logic to apply a `Mono.transform()` operator for a returned from the handler `Mono` reply
* Fix `WebFluxRequestExecutingMessageHandler` to return a `Mono.then()` instead of an explicit subscription -
it happens downstream anyway during reply producing with a proper error handling, too
* Demonstrate `ReactiveRequestHandlerAdvice` in the `RSocketDslTests` - without `retry()` it fails
* Add `ConsumerEndpointSpec.customizeMonoReply()` for convenience
* Document `ReactiveRequestHandlerAdvice` feature
* * Fix language in docs
Copy file name to clipboardExpand all lines: spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractMessageProducingHandler.java
Copy file name to clipboardExpand all lines: spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractReplyProducingMessageHandler.java
+1-1
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
/*
2
-
* Copyright 2002-2019 the original author or authors.
2
+
* Copyright 2002-2020 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
Copy file name to clipboardExpand all lines: spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/outbound/RSocketOutboundGateway.java
Copy file name to clipboardExpand all lines: spring-integration-webflux/src/main/java/org/springframework/integration/webflux/outbound/WebFluxRequestExecutingMessageHandler.java
Copy file name to clipboardExpand all lines: src/reference/asciidoc/handler-advice.adoc
+23-1
Original file line number
Diff line number
Diff line change
@@ -56,6 +56,7 @@ In addition to providing the general mechanism to apply AOP advice classes, Spri
56
56
* `ExpressionEvaluatingRequestHandlerAdvice` (described in <<expression-advice>>)
57
57
* `RateLimiterRequestHandlerAdvice` (described in <<rate-limiter-advice>>)
58
58
* `CacheRequestHandlerAdvice` (described in <<cache-advice>>)
59
+
* `ReactiveRequestHandlerAdvice` (described in <<reactive-advice>>)
59
60
60
61
[[retry-advice]]
61
62
===== Retry Advice
@@ -514,6 +515,7 @@ This configuration functionality is similar to Spring Framework's `@CacheConfig`
514
515
If a `CacheManager` is not provided, a single bean is resolved by default from the `BeanFactory` in the `CacheAspectSupport`.
515
516
516
517
The following example configures two advices with different set of caching operations:
518
+
517
519
====
518
520
[source, java]
519
521
----
@@ -549,6 +551,26 @@ public Message<?> service(Message<?> message) {
549
551
----
550
552
====
551
553
554
+
[[reactive-advice]]
555
+
==== Reactive Advice
556
+
557
+
Starting with version 5.3, a `ReactiveRequestHandlerAdvice` can be used for request message handlers producing a `Mono` replies.
558
+
A `BiFunction<Message<?>, Mono<?>, Publisher<?>>` has to be provided for this advice and it is called from the `Mono.transform()` operator on a reply produced by the intercepted `handleRequestMessage()` method implementation.
559
+
Typically such a `Mono` customization is necessary when we would like to control network fluctuations via `timeout()`, `retry()` and similar support operators.
560
+
For example when we can an HTTP request over WebFlux client, we could use below configuration to not wait for response more than 5 seconds:
e -> e.customizeMonoReply((message, mono) -> mono.timeout(Duration.ofSeconds(5))));
567
+
----
568
+
====
569
+
570
+
The `message` argument is the request message for the message handler and can be used to determine request-scope attributes.
571
+
The `mono` argument is the result of this message handler's `handleRequestMessage()` method implementation.
572
+
A nested `Mono.transform()` can also be called from this function to apply, for example, a https://spring.io/projects/spring-cloud-circuitbreaker[Reactive Circuit Breaker].
573
+
552
574
[[custom-advice]]
553
575
==== Custom Advice Classes
554
576
@@ -678,7 +700,7 @@ The following example shows `<transactional>` in use:
0 commit comments