How does project reactor or spring webflux – correctly fetches serverwebexchange object?

I am trying to build something like threadlocal but for webflux. My question is how does the context or serverwebexchange object passed down from one class to another (filters, controllers, services, etc) when a single can be used by multiple requets?

How does it work internally?

I am using threadlocal to pass down custom information. Need alternative to it with project reactor or java 20 virtual threads concepts coming live.

I am building this common piece of code which should work in any latest jdk or spring framework

It looks like you are aiming for Context from the Project Reactor, which lets you pass the contextual data through Reactive sequence and it is tied to each Subscriber. They have it very well documented here:
Adding a Context to a Reactive Sequence

Leave a Comment