Package com.google.genkit.core.middleware
package com.google.genkit.core.middleware
Middleware support for Genkit Java.
This package provides a middleware pattern implementation for wrapping action execution with pre-processing and post-processing logic. Middleware can be used for:
- Logging and monitoring
- Request/response transformation
- Caching
- Rate limiting
- Retry logic
- Validation
- Error handling
Example usage:
// Create a middleware chain
MiddlewareChain<String, String> chain = new MiddlewareChain<>();
chain.use(CommonMiddleware.logging("myAction"));
chain.use(CommonMiddleware.retry(3, 100));
// Execute with middleware
String result = chain.execute(input, context, (ctx, req) -> {
// Actual action logic
return "Hello, " + req;
});
- See Also:
-
ClassDescriptionCommonMiddleware provides factory methods for creating commonly-used middleware functions.Middleware<I,
O> Middleware is a function that wraps action execution, allowing pre-processing and post-processing of requests and responses.MiddlewareCache is a simple cache interface for use with caching middleware.MiddlewareChain<I,O> MiddlewareChain manages a list of middleware and provides execution of the complete chain.MiddlewareNext<I,O> MiddlewareNext represents the next function in the middleware chain.SimpleCache<V>SimpleCache is a thread-safe in-memory cache implementation for use with caching middleware.