Principle:A2aproject A2a java Event Queue Backpressure Streaming
| Knowledge Sources | |
|---|---|
| Domains | Distributed_Systems, Reactive_Systems, Concurrency |
| Last Updated | 2026-10-29 00:00 GMT |
Overview
A backpressure-managed event queue architecture that enables real-time streaming of task updates from a single producer to multiple subscribers with bounded memory.
Description
Event Queue Backpressure Streaming is the mechanism by which the A2A SDK delivers task updates from agent executors to clients in real time. The architecture uses a hierarchical queue structure (MainQueue → ChildQueue) where a single producer (the AgentExecutor via AgentEmitter) enqueues events into a MainQueue, and multiple subscribers each consume from their own ChildQueue that receives fan-out copies.
The problem this solves is the slow consumer problem in streaming systems: if an agent produces events faster than a client can consume them, unbounded buffering leads to memory exhaustion. The EventQueue uses semaphore-based backpressure — the producer blocks on `enqueueEvent()` when the queue is full, naturally throttling the agent to the speed of the slowest active subscriber.
In the broader landscape, this is an instance of the Reactive Streams pattern with bounded buffering, similar to RxJava's `BackpressureStrategy.BUFFER` with a capacity limit, or Kafka's consumer group model where each consumer in a group gets its own copy of the stream. The MainQueue/ChildQueue hierarchy is a fan-out broadcast with per-subscriber buffering.
The Mutiny Zero library provides the reactive streams bridge (`ZeroPublisher`) that converts the blocking queue into a reactive stream compatible with SSE (Server-Sent Events) transport.
Usage
Use this principle when:
- Building agents that stream results (LLM token streaming, progressive artifacts)
- Supporting multiple concurrent subscribers to the same task's event stream
- Designing systems where producers must be throttled to consumer speed
- Implementing resubscription after client disconnection (late reconnections)
Theoretical Basis
The queue hierarchy uses a two-level fan-out model:
AgentExecutor → AgentEmitter → MainQueue (bounded, semaphore-backed)
├── ChildQueue_1 → Subscriber_1 (SSE stream)
├── ChildQueue_2 → Subscriber_2 (SSE stream)
└── ChildQueue_N → Subscriber_N (SSE stream)
Backpressure:
MainQueue.enqueueEvent(event):
semaphore.acquire() // blocks if queue full (DEFAULT_QUEUE_SIZE=1000)
queue.put(event)
fanOutToAllChildQueues(event)
ChildQueue.dequeueEventItem(timeout):
event = queue.poll(timeout)
if event.isTerminal(): close() // COMPLETED, FAILED, CANCELED
return event
Terminal events (COMPLETED, FAILED, CANCELED) close the queue and propagate to all ChildQueues, ending all subscriber streams.
The EventConsumer bridges the blocking queue to a reactive stream:
EventConsumer(EventQueue, Executor):
→ ZeroPublisher (Mutiny Zero)
→ SSE stream to client
→ respects reactive streams contract (request n items)
Practical Guide
To use event streaming as an agent developer:
- Call `AgentEmitter.addArtifact()` to stream content incrementally
- Call `AgentEmitter.complete()` to signal task completion (closes the queue)
- The framework handles backpressure automatically — if the client is slow, your `enqueueEvent()` call blocks
To use event streaming as a client developer:
- Enable streaming via `ClientConfig.Builder.setStreaming(true)`
- Register event consumers via `ClientBuilder.addConsumer()`
- Events arrive asynchronously as `TaskUpdateEvent` instances
Related Pages
Implemented By
- Implementation:A2aproject_A2a_java_EventQueue
- Implementation:A2aproject_A2a_java_Client
- Implementation:A2aproject_A2a_java_ClientEvent_Pattern
- Implementation:A2aproject_A2a_java_ResultAggregator
- Implementation:A2aproject_A2a_java_AsyncUtils
- Implementation:A2aproject_A2a_java_QueueManager_SPI
- Implementation:A2aproject_A2a_java_PushNotification_SPI
- Implementation:A2aproject_A2a_java_BasePushNotificationSender
- Implementation:A2aproject_A2a_java_SSE_Parsing_Stack
- Implementation:A2aproject_A2a_java_Server_Config_and_ThreadPool