Configuration Util
| GitHub Repository | https://github.com/AirCommerce/util-configuration |
The Configuration Util (util-configuration) is a shared Spring Boot client library embedded directly into consumer microservices across the AirCommerce platform. It implements the client side of the dual-tier configuration architecture, providing dynamic field injection, in-memory caching, and automatic event-driven cache invalidation.
Architecture
Section titled “Architecture”This view illustrates how the Configuration Util library embeds within consumer microservices (such as iFlyRes Connector and Business Orchestrator Service), boots configurations from the Configuration Service, and listens for lifecycle change events:
Key Capabilities
Section titled “Key Capabilities”- Zero-Latency In-Memory Reads: Caches active configuration values in local heap memory (Local Configuration Cache), delivering sub-millisecond reads without HTTP overhead on latency-critical transaction paths.
- Dynamic Field Injection: Uses the
@ConfigurationValueannotation to automatically bind remote configuration parameters to bean properties at runtime. - Resilient Local Fallback: Safely captures initial hardcoded field values during application startup, preventing boot failures when keys are absent on the server and cleanly reverting to local defaults upon key deletion (ADR 0003).
- Event-Driven Cache Invalidation: Listens to targeted cache invalidation events over Spring Cloud Bus / RabbitMQ via dynamic namespace routing (ADR 0006) and evicts modified keys in real time.
Usage in Consumer Microservices
Section titled “Usage in Consumer Microservices”1. Maven Dependency
Section titled “1. Maven Dependency”Consumer services import the starter via the centralized version catalog (ADR 0005):
<dependency> <groupId>cloud.aircommerce</groupId> <artifactId>util-configuration</artifactId></dependency>2. Declaring Configuration Namespaces
Section titled “2. Declaring Configuration Namespaces”Consumer microservices declare the namespaces they need in application.yaml:
spring: application: name: connector-iflyres
aircommerce: configuration: namespaces: - common - iflyres-connectorUnder the hood, BusMatcherConfig automatically bridges aircommerce.configuration.namespaces into Spring Cloud Bus’s ServiceMatcher. This enables the microservice to receive invalidation events for both common:** and iflyres-connector:** while safely ignoring unrelated namespaces, eliminating the need to duplicate definitions under spring.cloud.config.name (ADR 0006).
3. Injecting Configuration Values
Section titled “3. Injecting Configuration Values”Annotate fields with @ConfigurationValue. The library automatically captures the developer’s default value and binds the runtime parameter:
@Componentpublic class PricingEngine {
@ConfigurationValue("pricing.dynamic-surcharge-enabled") private Boolean dynamicSurchargeEnabled = Boolean.FALSE;
@ConfigurationValue("pricing.max-ancillary-discount-pct") private Integer maxDiscountPercentage = 15;
@ConfigurationValue("pricing.ancillary-fee-matrix") private List<TableRow> ancillaryFeeMatrix = List.of();
public boolean isSurchargeActive() { return Boolean.TRUE.equals(dynamicSurchargeEnabled); }
public BigDecimal resolveFee(String targetChannel) { return ancillaryFeeMatrix.stream() .filter(row -> row.getString("channel").filter(targetChannel::equals).isPresent()) .filter(row -> row.getBoolean("active", false)) .findFirst() .map(row -> row.getBigDecimal("feeAmount", BigDecimal.ZERO)) .orElse(BigDecimal.ZERO); }}Typed Table (List<TableRow>) Accessors & Behavior
Section titled “Typed Table (List<TableRow>) Accessors & Behavior”ConfigurationTypeUtils maps List<TableRow> fields to ConfigurationType.TABLE, and ConfigurationValueExtractor extracts TableConfigurationResponse#getRows() (throwing ConfigurationExtractionException on type mismatch):
TableRowAccessors: Read typed cell values safely viagetString(columnKey)(Optional<String>),getBoolean(columnKey, defaultValue),getBigDecimal(columnKey, defaultValue), andgetList(columnKey)(List<String>). Malformed or absent cells return the supplied fallback (Optional.empty(),defaultValue, orCollections.emptyList()).- Lenient Scalar Coercion:
TableCell.LenientStringDeserializeraccepts JSON strings, numbers, and booleans onvaluewhile rejecting non-scalar{}or[]tokens. - Live Reload, Fallback & Actuator:
UPDATEDlifecycle events refresh the injectedList<TableRow>field in place; absent startup keys retain the field’s default list andDELETEDevents revert it to that baseline (ADR 0003).ConfigurationActuatorEndpointexposesremoteType = "TABLE"in/actuator/aircommerceConfig(ADR 0010).
Lifecycle & Resiliency Mechanics
Section titled “Lifecycle & Resiliency Mechanics”Bootstrap Sequence
Section titled “Bootstrap Sequence”- During Spring Application Context initialization,
ConfigurationValueInjectorscans beans for@ConfigurationValue. - Initial hardcoded values are extracted via reflection and stored in the
ConfigurationFieldRegistryas immutable baselines. - The library initiates a Feign HTTP request to the Configuration Service API to retrieve the latest configuration documents for the service’s namespace.
- Successfully retrieved remote values populate the local cache and update the annotated fields. If a remote key is absent, the local baseline is preserved without throwing startup exceptions.
Runtime Invalidation
Section titled “Runtime Invalidation”When an operator updates a configuration via the Configuration UI, the Configuration Service dispatches a ConfigurationChangedEvent targeted to namespace:**. The consumer’s custom ServiceMatcher (BusMatcherConfig) intercepts events matching any of its declared namespaces, invalidates the corresponding entry in LocalCache, and re-evaluates field bindings immediately (ADR 0006).
Architecture Decisions
Section titled “Architecture Decisions”| ADR | Status | Date | Title |
|---|---|---|---|
| ADR-0010 | Accepted | 2026-11-20 | Typed Table Configuration |
| ADR-0006 | Accepted | 2026-10-13 | Dynamic Bus Routing for Custom Configuration Namespaces |
| ADR-0004 | Accepted | 2026-09-11 | Configuration Visibility Actuator Endpoint |
| ADR-0003 | Accepted | 2026-09-11 | Graceful Default Value Fallbacks |
High-Level Designs
Section titled “High-Level Designs”None