Interface PublisherAdapter
public interface PublisherAdapter
SPI for adapting the canonical reactive stream used internally by non-blocking streaming AI Services —
a
Flow.Publisher — to a third-party reactive type (e.g. Reactor Flux, Mutiny Multi).
It is one-directional: an AI Service method declared to return such a type is satisfied by
fromPublisher(Type, Flow.Publisher), which wraps the framework-produced Flow.Publisher
into an instance of the declared type.
The element type of the supplied publisher matches the element type of the declared return type: it is
either AiServiceStreamingEvent (the rich event stream) or String (text-only — the text of
each partial response). Implementations must not assume one or the other; they only convert the container.
Flow.Publisher of AiServiceStreamingEvent and of String are handled natively and do
not require an adapter. Implementations are discovered via the ServiceLoader mechanism.
- Since:
- 1.20.0
-
Method Summary
Modifier and TypeMethodDescriptionbooleanfromPublisher(Type type, Flow.Publisher<?> publisher) Produces an instance of the adapted type (e.g. aFlux<String>) from the framework-producedFlow.Publisher.
-
Method Details
-
canAdapt
- Parameters:
type- the AI Service method's declared return type, such asFlux<String>orMulti<AiServiceStreamingEvent>.- Returns:
trueif this adapter handles the given type.
-
fromPublisher
Produces an instance of the adapted type (e.g. aFlux<String>) from the framework-producedFlow.Publisher.- Parameters:
type- the declared type to produce (e.g.Flux<String>).publisher- the framework-produced reactive stream, whose element type matches the element type oftype(eitherAiServiceStreamingEventorString).
-