Synchronous Interceptors
Synchronous interceptors operate in a blocking manner, directly influencing the real-time flow of messages.
When a message encounters a synchronous interceptor, the message flow is paused. The interceptor processes the message, which may include real-time data manipulation or validation. The message flow then resumes only after the interceptor has completed its operation and returned a processed response.
This execution model is ideal when the output or modification performed by the interceptor is a prerequisite for subsequent steps in the communication sequence. For instance, a synchronous interceptor could be used for message validation, routing decisions, or transforming data format before it reaches its final destination.
How It Works
Synchronous interceptors follow a blocking execution model, ensuring that the message flow does not proceed until processing is complete.
adk.intercept("validator", (payload, resolve, reject) => {
if (payload.isValid) {
resolve({ status: "validated", data: payload });
} else {
reject("Validation failed");
}
});
Here's how the synchronous interceptor works:
- Message Capture: The interceptor is triggered when a message enters the channel.
- Processing: The interceptor runs its logic (validation, transformation, or routing decisions).
- Response: The interceptor must return a resolve (success) or reject (failure).
- Pipeline Continuation: The message resumes its journey only after the interceptor responds.