跳到主要内容
版本:7.0.3

背景

Hunyuan 7b 中英对照 Context

属性提供了一种方便的方式将信息传递给过滤链,但它们只影响当前请求。如果你想传递的信息能够传播到其他嵌套的请求中(例如,通过flatMap),或者在之后的请求中仍然生效(例如,通过concatMap),那么你就需要使用Reactor的Context

Reactor的Context需要在反应式链(reactive chain)的末端被填充(populated),以便能够应用于所有操作。例如:

WebClient client = WebClient.builder()
.filter((request, next) ->
Mono.deferContextual(contextView -> {
String value = contextView.get("foo");
// ...
}))
.build();

client.get().uri("https://example.org/")
.retrieve()
.bodyToMono(String.class)
.flatMap(body -> {
// perform nested request (context propagates automatically)...
})
.contextWrite(context -> context.put("foo", ...));