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 Details

    • canAdapt

      boolean canAdapt(Type type)
      Parameters:
      type - the AI Service method's declared return type, such as Flux<String> or Multi<AiServiceStreamingEvent>.
      Returns:
      true if this adapter handles the given type.
    • fromPublisher

      Object fromPublisher(Type type, Flow.Publisher<?> publisher)
      Produces an instance of the adapted type (e.g. a Flux<String>) from the framework-produced Flow.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 of type (either AiServiceStreamingEvent or String).