Class BasePushNotificationSender
- All Implemented Interfaces:
PushNotificationSender
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final StringCDI@Namedqualifier ("a2a.pushNotificationDispatch") for an optional application-providedExecutorused to dispatch push notifications asynchronously.Fields inherited from interface org.a2aproject.sdk.server.tasks.PushNotificationSender
NOOP -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedNo-args constructor for CDI proxy creation.BasePushNotificationSender(PushNotificationConfigStore configStore, jakarta.enterprise.inject.Instance<PushNotificationPayloadFormatter> formatters, PushNotificationUrlValidator urlValidator, jakarta.enterprise.inject.Instance<A2AHttpClient> httpClient, jakarta.enterprise.inject.Instance<A2AHttpClient> propagatingClient, jakarta.enterprise.inject.Instance<Executor> instrumentedExecutor, jakarta.enterprise.inject.Instance<Executor> dispatchExecutor) CDI injection constructor.BasePushNotificationSender(PushNotificationConfigStore configStore, A2AHttpClient httpClient, List<PushNotificationPayloadFormatter> formatters, PushNotificationUrlValidator urlValidator) BasePushNotificationSender(PushNotificationConfigStore configStore, A2AHttpClient httpClient, PushNotificationUrlValidator urlValidator) BasePushNotificationSender(PushNotificationConfigStore configStore, PushNotificationUrlValidator urlValidator) -
Method Summary
Modifier and TypeMethodDescriptionprotected @Nullable StringextractTaskId(StreamingEventKind event) Extracts the task ID from a streaming event.booleansendNotification(StreamingEventKind event, @Nullable Task taskSnapshot) Sends a push notification containing a streaming event.
-
Field Details
-
DEFAULT_PAGE_SIZE
public static final int DEFAULT_PAGE_SIZE- See Also:
-
DISPATCH_EXECUTOR_NAME
CDI@Namedqualifier ("a2a.pushNotificationDispatch") for an optional application-providedExecutorused to dispatch push notifications asynchronously.Applications can produce a bean with this name to supply a custom thread pool (e.g. for sizing or monitoring). When an instrumentation module (such as the OpenTelemetry server extra) is present, it produces an
@InstrumentedExecutorthat wraps the application's@Namedexecutor (or a default pool) with context propagation.Resolution order (see the
CDI constructor):@InstrumentedExecutor(instrumented wrapper)@Named("a2a.pushNotificationDispatch")Executor(application-provided)ForkJoinPool.commonPool()as last resort
- See Also:
-
-
Constructor Details
-
BasePushNotificationSender
protected BasePushNotificationSender()No-args constructor for CDI proxy creation. CDI requires a non-private constructor to create proxies for @ApplicationScoped beans. All fields are initialized by the @Inject constructor during actual bean creation. -
BasePushNotificationSender
public BasePushNotificationSender(PushNotificationConfigStore configStore, PushNotificationUrlValidator urlValidator) -
BasePushNotificationSender
@Inject public BasePushNotificationSender(PushNotificationConfigStore configStore, jakarta.enterprise.inject.Instance<PushNotificationPayloadFormatter> formatters, PushNotificationUrlValidator urlValidator, jakarta.enterprise.inject.Instance<A2AHttpClient> httpClient, jakarta.enterprise.inject.Instance<A2AHttpClient> propagatingClient, jakarta.enterprise.inject.Instance<Executor> instrumentedExecutor, @Named("a2a.pushNotificationDispatch") jakarta.enterprise.inject.Instance<Executor> dispatchExecutor) CDI injection constructor.The HTTP client is resolved in order of preference:
- A
@Instrumentedbean (e.g. one produced by the OpenTelemetry server extra, which wraps the application's client with trace-context injection) - An unqualified
A2AHttpClientbean provided by the application (custom mTLS, proxy, authentication, etc.) A2AHttpClientFactory.create(A2AHttpClientConfiguration)as last resort
The dispatch executor is resolved in order of preference:
- An
@InstrumentedExecutor(e.g. one produced by the OpenTelemetry server extra, which wraps the application's executor with context propagation) - A
@Named("a2a.pushNotificationDispatch")Executorprovided by the application ForkJoinPool.commonPool()as last resort
- Parameters:
configStore- the store for push notification configurationsformatters- optional formatters for protocol-version-specific payloadsurlValidator- validates push notification URLs to prevent SSRFhttpClient- optional CDI-provided HTTP clientpropagatingClient- optional context-propagating HTTP client that wraps the application's client with observability instrumentationinstrumentedExecutor- optional instrumented executor with context propagationdispatchExecutor- optional named executor for async dispatch
- A
-
BasePushNotificationSender
public BasePushNotificationSender(PushNotificationConfigStore configStore, A2AHttpClient httpClient, PushNotificationUrlValidator urlValidator) -
BasePushNotificationSender
public BasePushNotificationSender(PushNotificationConfigStore configStore, A2AHttpClient httpClient, List<PushNotificationPayloadFormatter> formatters, PushNotificationUrlValidator urlValidator)
-
-
Method Details
-
sendNotification
Description copied from interface:PushNotificationSenderSends a push notification containing a streaming event.Called after the event has been persisted to
TaskStore. The payload format depends on the protocol version used to register the push notification configuration.- v1.0 (default): The event is wrapped in a StreamResponse format (per A2A spec section 4.3.3) with the appropriate oneof field set (task, message, statusUpdate, or artifactUpdate).
- v0.3: The payload is a v0.3
TaskJSON object, using the providedtaskSnapshot.Messageevents are skipped.
Retrieve push notification URLs or messaging configurations from
Supported event types:PushNotificationConfigStoreusing the task ID extracted from the event.Error Handling: Return
falseon delivery failures (network errors, HTTP errors). Throwing is reserved for precondition violations such as a missing task ID or an unsupported event type — these signal caller bugs. Callers catch all exceptions so neither case fails the client request.- Specified by:
sendNotificationin interfacePushNotificationSender- Parameters:
event- the streaming event to send.taskSnapshot- the current state of the task after the event has been applied. Used by formatters for older protocol versions that require the full task state in notifications.- Returns:
trueif all notifications were delivered successfully,falseif one or more deliveries failed
-
extractTaskId
Extracts the task ID from a streaming event.- Parameters:
event- the streaming event- Returns:
- the task ID, or
nullif the event type does not carry one (e.g. aMessagewithout a task ID) - Throws:
IllegalStateException- if the event is not a recognizedStreamingEventKindsubtype
-