|
| 1 | +# A2A Java SDK - MicroProfile Config Integration |
| 2 | + |
| 3 | +This optional integration module provides MicroProfile Config support for the A2A Java SDK configuration system. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The A2A Java SDK core uses the `A2AConfigProvider` interface for configuration, with default values loaded from `META-INF/a2a-defaults.properties` files on the classpath. |
| 8 | + |
| 9 | +This module provides `MicroProfileConfigProvider`, which integrates with MicroProfile Config to allow configuration via: |
| 10 | +- `application.properties` |
| 11 | +- Environment variables |
| 12 | +- System properties (`-D` flags) |
| 13 | +- Custom ConfigSources |
| 14 | + |
| 15 | +## Quick Start |
| 16 | + |
| 17 | +### 1. Add Dependency |
| 18 | + |
| 19 | +```xml |
| 20 | +<dependency> |
| 21 | + <groupId>io.github.a2asdk</groupId> |
| 22 | + <artifactId>a2a-java-sdk-microprofile-config</artifactId> |
| 23 | + <version>${io.a2a.sdk.version}</version> |
| 24 | +</dependency> |
| 25 | +``` |
| 26 | + |
| 27 | +### 2. Configure Properties |
| 28 | + |
| 29 | +Once the dependency is added, you can override any A2A configuration property: |
| 30 | + |
| 31 | +**application.properties:** |
| 32 | +```properties |
| 33 | +# Executor configuration |
| 34 | +a2a.executor.core-pool-size=10 |
| 35 | +a2a.executor.max-pool-size=100 |
| 36 | + |
| 37 | +# Timeout configuration |
| 38 | +a2a.blocking.agent.timeout.seconds=60 |
| 39 | +a2a.blocking.consumption.timeout.seconds=10 |
| 40 | +``` |
| 41 | + |
| 42 | +**Environment variables:** |
| 43 | +```bash |
| 44 | +export A2A_EXECUTOR_CORE_POOL_SIZE=10 |
| 45 | +export A2A_BLOCKING_AGENT_TIMEOUT_SECONDS=60 |
| 46 | +``` |
| 47 | + |
| 48 | +**System properties:** |
| 49 | +```bash |
| 50 | +java -Da2a.executor.core-pool-size=10 -jar your-app.jar |
| 51 | +``` |
| 52 | + |
| 53 | +## How It Works |
| 54 | + |
| 55 | +The `MicroProfileConfigProvider` implementation: |
| 56 | + |
| 57 | +1. **First tries MicroProfile Config** - Checks `application.properties`, environment variables, system properties, and custom ConfigSources |
| 58 | +2. **Falls back to defaults** - If not found, uses values from `META-INF/a2a-defaults.properties` provided by core modules and extras |
| 59 | +3. **Priority 50** - Can be overridden by custom providers with higher priority |
| 60 | + |
| 61 | +## Configuration Fallback Chain |
| 62 | + |
| 63 | +``` |
| 64 | +MicroProfile Config Sources (application.properties, env vars, -D flags) |
| 65 | + ↓ (not found?) |
| 66 | +META-INF/a2a-defaults.properties (from server-common) |
| 67 | + ↓ (not found?) |
| 68 | +META-INF/a2a-defaults.properties (from extras modules) |
| 69 | + ↓ (not found?) |
| 70 | +IllegalArgumentException |
| 71 | +``` |
| 72 | + |
| 73 | +## Available Configuration Properties |
| 74 | + |
| 75 | +See the [main README](../../README.md#configuration-system) for a complete list of configuration properties. |
| 76 | + |
| 77 | +## Framework Compatibility |
| 78 | + |
| 79 | +This module works with any MicroProfile Config implementation: |
| 80 | + |
| 81 | +- **Quarkus** - Built-in MicroProfile Config support |
| 82 | +- **Helidon** - Built-in MicroProfile Config support |
| 83 | +- **Open Liberty** - Built-in MicroProfile Config support |
| 84 | +- **WildFly/JBoss EAP** - Add `smallrye-config` dependency |
| 85 | +- **Other Jakarta EE servers** - Add MicroProfile Config implementation |
| 86 | + |
| 87 | +## Custom Config Providers |
| 88 | + |
| 89 | +If you're using a different framework (Spring, Micronaut, etc.), you can implement your own `A2AConfigProvider`: |
| 90 | + |
| 91 | +```java |
| 92 | +import io.a2a.server.config.A2AConfigProvider; |
| 93 | +import io.a2a.server.config.DefaultValuesConfigProvider; |
| 94 | +import jakarta.enterprise.context.ApplicationScoped; |
| 95 | +import jakarta.enterprise.inject.Alternative; |
| 96 | +import jakarta.annotation.Priority; |
| 97 | +import jakarta.inject.Inject; |
| 98 | + |
| 99 | +@ApplicationScoped |
| 100 | +@Alternative |
| 101 | +@Priority(100) // Higher than MicroProfileConfigProvider's priority of 50 |
| 102 | +public class SpringConfigProvider implements A2AConfigProvider { |
| 103 | + |
| 104 | + @Inject |
| 105 | + Environment env; |
| 106 | + |
| 107 | + @Inject |
| 108 | + DefaultValuesConfigProvider defaultValues; |
| 109 | + |
| 110 | + @Override |
| 111 | + public String getValue(String name) { |
| 112 | + String value = env.getProperty(name); |
| 113 | + if (value != null) { |
| 114 | + return value; |
| 115 | + } |
| 116 | + // Fallback to defaults |
| 117 | + return defaultValues.getValue(name); |
| 118 | + } |
| 119 | + |
| 120 | + @Override |
| 121 | + public Optional<String> getOptionalValue(String name) { |
| 122 | + String value = env.getProperty(name); |
| 123 | + if (value != null) { |
| 124 | + return Optional.of(value); |
| 125 | + } |
| 126 | + return defaultValues.getOptionalValue(name); |
| 127 | + } |
| 128 | +} |
| 129 | +``` |
| 130 | + |
| 131 | +## Implementation Details |
| 132 | + |
| 133 | +- **Package**: `io.a2a.integrations.microprofile` |
| 134 | +- **Class**: `MicroProfileConfigProvider` |
| 135 | +- **Priority**: 50 (can be overridden) |
| 136 | +- **Scope**: `@ApplicationScoped` |
| 137 | +- **Dependencies**: MicroProfile Config API, A2A SDK server-common |
| 138 | + |
| 139 | +## Reference Implementations |
| 140 | + |
| 141 | +The A2A Java SDK reference implementations (Quarkus-based) automatically include this integration module, so MicroProfile Config properties work out of the box. |
| 142 | + |
| 143 | +If you're building a custom server implementation, add this dependency to enable property-based configuration. |
0 commit comments