Coder Social home page Coder Social logo

Comments (2)

rstoyanchev avatar rstoyanchev commented on June 14, 2024

Those are related issues but not the same. It means after the changes, the following works:

@GetMapping(path = "/", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<Greeting> stream() {
	return Flux.interval(Duration.ofSeconds(1))
			.doOnNext(o -> {
				RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
				System.out.println("RequestAttributes: " + attributes);
			})
			.map(value -> new Greeting("bar"));
}

When Spring MVC subscribes to the Flux, it uses Micrometer Context Propagation to capture ThreadLocals it knows about, and inserts those into the Reactor Context where they can be accessed as key-value pairs. In addition, Reactor supports restoring ThreadLocals in the Flux chain, which is why doOnNext above finds the request.

The HttpMessageConverter, however, is called from the subscriber to the Flux, and it's not covered by the above, and message converters generally don't depend on thread local context.

from spring-framework.

dsyer avatar dsyer commented on June 14, 2024

I'm not sure I follow yet - isn't the subscriber Spring MVC, which you said would propagate the context? By "works" you mean "prints out request attributes", I guess, but that's not helpful if the HttpMessageConverter cannot access the thread local context. What I really want to do is render a View in the message converter, so I'm going to need the web context. Is there another way? Can we make it work somehow without leaking thread context - I don't think users (i.e. me) should be trusted to get that right without help from the framework?

from spring-framework.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.