Skip to main content

Asynchronous Interceptors

Asynchronous interceptors operate independently, allowing the message flow to continue without waiting for their complete processing.

Upon encountering an asynchronous interceptor, the message data is dispatched to the interceptor for processing. The messaging flow then proceeds immediately after receiving an initial acknowledgment from the interceptor server, without waiting for the interceptor to complete its full processing or return a detailed response.

This non-blocking approach is perfectly suited for tasks where immediate feedback is not critical to the primary message delivery process. Common use cases for asynchronous interceptors include logging, performance monitoring, and data analytics.

How It Works

Asynchronous interceptors follow a non-blocking execution model, meaning the message pipeline continues without waiting for the interceptor to finish.

adk.intercept("data_processor", async (payload, resolve, reject) => {
try {
const result = await externalApiCall(payload);
resolve(result);
} catch (error) {
reject(error.message);
}
});

Here's how asynchronous interceptor works:

  1. Message Capture: The interceptor is triggered when a message enters the channel.
  2. Background Processing: The interceptor begins its task (e.g., API call, database query, logging) in parallel.
  3. Pipeline Continuation: The message immediately moves on to the next interceptor or recipient.
  4. Deferred Response: Once the async task finishes, the interceptor can return results or handle side effects independently of the main pipeline.