liveBook · Manning

Flux

As explained in Spring AI in Action

Flux is a Project Reactor reactive type that emits zero or more data elements asynchronously as they become available.

Flux is a Project Reactor reactive type that emits zero or more data elements asynchronously as they become available. In a Spring AI chat application, returning Flux<String> lets generated response fragments reach the interface progressively instead of waiting for the complete answer. section 3.4.3

Use Flux for streaming responses by:

  • Calling ChatClient's stream() method instead of call(). section 3.4.3
  • Returning the resulting Flux<String> from the service and controller. section 3.4.3
  • Configuring the endpoint for a streamed response rather than application/json. section 3.4.3

Streaming an LLM answer

A board-game service can return generated content through Flux<String>; the client may receive short fragments, often approximately one word at a time, while generation continues. section 3.4.3

How Spring AI in Action covers it

How deep it goes
Defines zero-to-many reactive emission and demonstrates service-controller integration, while deferring broader Project Reactor details.
Examples
Uses a board-game question service, streamed battle-card answers, Flux<String>, and HTTPie demonstrations.
What it assumes
Assumes Spring AI ChatClient and basic controller usage, while defining Flux's core behavior directly.
What you can do after
Apply Flux through ChatClient stream(), reactive return types, and streamed endpoint configuration.
How it connects
Connects reactive programming with Project Reactor, Spring AI ChatClient, controllers, MIME types, and Mono.

Also explained in

Compare how 3 books explain Flux →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring AI in Action. The section links point to the parts of the book it draws on.