惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
博客园 - 叶小钗
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
腾讯CDC
S
SegmentFault 最新的问题
D
DataBreaches.Net
Hugging Face - Blog
Hugging Face - Blog
L
LangChain Blog
Recent Announcements
Recent Announcements
阮一峰的网络日志
阮一峰的网络日志
N
Netflix TechBlog - Medium
大猫的无限游戏
大猫的无限游戏
M
MIT News - Artificial intelligence
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 三生石上(FineUI控件)
F
Fortinet All Blogs
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Martin Fowler
Martin Fowler
雷峰网
雷峰网
J
Java Code Geeks
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
小众软件
小众软件
云风的 BLOG
云风的 BLOG
T
Tailwind CSS Blog

博客园 - 荣锋亮

pg-boss 基于pg 的node 队列job 服务 Omnigres 基于pg的开发平台 zerofs 支持native kernel client multigres pg 版的Vitess drizzle-duckdb duckdb drizzle orm client dumbodb 面向文档db 的版本管理db doltlite sqlite 的版本控制 doltgresql pg 的dolt 服务 TokenHub 基于golang 的llm proxy 服务 duckgres PostHog 开源的通过pg协议暴露duckdb服务能力 jenkins 2.568.1 publish over ssh java.lang.NoSuchMethodError: 'java.lang.Object jenkins.plugins.publish_over_ssh.BapSshHostConfiguration 问题 scriptc vercel 开源的ts 转native 编译器 itty-router 轻量的microrouter drizzle-proxy 格式简单说明 drizzle-proxy 简单说明 duckdb iceberg rest catalog连接的一个问题 supabase wrappers pg 扩展服务 ice 运行简单说明 pgnats pg 的nats 扩展 ice 轻量iceberg rest catalog 服务 zerofs v2.1.0 支持无缝的ha 以及恢复了 liteparse 的可视化引用 VaultS3 与zerofs 集成测试 VaultS3 一个轻量的s3 兼容服务 liteparse-server liteparse rest&grpc服务 smoothdb 兼容postgrest的服务 fluxbase 基于golang 开发的兼容supabase的服务 pg_durable 微软开源的基于pg 的持久运行扩展 liteparse ocr api 规范 基于litserve 以及RapidOCR扩展一个liteparse ocr 服务
context-propagation spring reactor 的上下文传递包
荣锋亮 · 2026-06-21 · via 博客园 - 荣锋亮

context-propagation 是一个比较强大的上下文传递包,对于上下文处理进行了一些抽象,可以兼容传统ThreadLocal的一些处理

参考玩法

包含了自动模式`Hooks.enableAutomaticContextPropagation();`

static final ThreadLocal<String> TL = new ThreadLocal<>();
    static final String TLKEY = "demo";

    public static void main(String[] args) throws InterruptedException {
        BlockHound.install();
        ReactorDebugAgent.init();
        Hooks.enableAutomaticContextPropagation();
        ContextRegistry.getInstance()
                .registerThreadLocalAccessor(
                        TLKEY,
                        TL::get,
                        TL::set,
                        TL::remove
                );
        TL.set("HELLO");
        var info = Mono.deferContextual(ctx ->
                        Mono.delay(Duration.ofSeconds(1))
                                // we're now in another thread, TL is not explicitly set
                                .map(v -> "delayed ctx[" + TLKEY + "]=" + ctx.getOrDefault(TLKEY, "not found") + ", TL=" + TL.get()))
                .block(); // returns "delayed ctx[TLKEY]=HELLO, TL=null" in default mode
        // returns "delayed ctx[TLKEY]=HELLO, TL=HELLO" in automatic mode
        System.out.println(info);
    }

说明

context-propagation 包是一个比较有用的,尤其在链路追踪场景中

参考资料

https://aabir-hassan.medium.com/demystifying-spring-webflux-the-reactor-context-part-4-3169d02ae2f4

https://docs.micrometer.io/context-propagation/reference/usage.html

https://github.com/micrometer-metrics/context-propagation

https://projectreactor.io/docs/core/3.8.6-SNAPSHOT/reference/advanced-contextPropagation.html