Skip to content

Commit 2046b11

Browse files
committed
spring-projectsGH-3869: Add Documentation.
1 parent 5b312ab commit 2046b11

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/reference/asciidoc/handler-advice.adoc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ In addition to providing the general mechanism to apply AOP advice classes, Spri
5757
* `RateLimiterRequestHandlerAdvice` (described in <<rate-limiter-advice>>)
5858
* `CacheRequestHandlerAdvice` (described in <<cache-advice>>)
5959
* `ReactiveRequestHandlerAdvice` (described in <<reactive-advice>>)
60+
* `ContextHolderRequestHandlerAdvice` (described in <<context-holder-advice>>)
61+
62+
[[expression-advice]]
6063

6164
[[retry-advice]]
6265
===== Retry Advice
@@ -571,6 +574,29 @@ The `message` argument is the request message for the message handler and can be
571574
The `mono` argument is the result of this message handler's `handleRequestMessage()` method implementation.
572575
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].
573576

577+
[[context-holder-advice]]
578+
==== Context Holder Advice
579+
Starting with version 6.1, the `ContextHolderRequestHandlerAdvice` has been introduced.
580+
Similar to the functionality introduced by the `DelegatingSessionFactory`, this advice provides the ability
581+
to take a specific key from the request message and store it in the context holder.
582+
The value of this key is then used in the `MessageHandler` implementation to perform some predefined logic.
583+
This key/value pair can be cleared from the context holder after the operation has been completed.
584+
585+
====
586+
[source, java]
587+
----
588+
@Bean
589+
ContextHolderRequestHandlerAdvice contextHolderRequestHandlerAdvice() {
590+
final Map<Object, SessionFactory<String>> factories = new HashMap<>();
591+
final DefaultSessionFactoryLocator<String> sff = new DefaultSessionFactoryLocator<>(factories, foo);
592+
final DelegatingSessionFactory<String> dsf = new DelegatingSessionFactory<>(sff);
593+
final Function<Message<?>, Object> keyProviderFn = m -> m.getHeaders().get("<KEY_NAME>");
594+
final Consumer<Object> contextSetHookFn = dsf::setThreadKey;
595+
final Consumer<Object> contextClearHookFn = key -> dsf.clearThreadKey();
596+
return new ContextHolderRequestHandlerAdvice(keyProviderFn, contextSetHookFn, contextClearHookFn);
597+
}
598+
----
599+
====
574600
[[custom-advice]]
575601
==== Custom Advice Classes
576602

0 commit comments

Comments
 (0)