I tried to use the context to set some value of Reactor3 in the filter of SpringCloud Gateway but in the controller,I can't get the value in the Context.
Actually, I am new to Reactor3. So please give me some tips or help, thank you very much!
//my GatewayFilter
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
return chain.filter(exchange)
.subscriberContext(ctx -> ctx.put("key", "hello gate"));
}
//my Controller
@ResponseBody
@RequestMapping("/test")
public Mono<String> test() {
return Mono.subscriberContext()
.map(ctx -> ctx.get("key"));
}
when I try to get the value of Context , it will throw an Exception "context is empty"