Skip to content

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.

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:

  • 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 @ConfigurationValue annotation 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.

Consumer services import the starter via the centralized version catalog (ADR 0005):

<dependency>
<groupId>cloud.aircommerce</groupId>
<artifactId>util-configuration</artifactId>
</dependency>

Consumer microservices declare the namespaces they need in application.yaml:

spring:
application:
name: connector-iflyres
aircommerce:
configuration:
namespaces:
- common
- iflyres-connector

Under 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).

Annotate fields with @ConfigurationValue. The library automatically captures the developer’s default value and binds the runtime parameter:

@Component
public 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):

  • TableRow Accessors: Read typed cell values safely via getString(columnKey) (Optional<String>), getBoolean(columnKey, defaultValue), getBigDecimal(columnKey, defaultValue), and getList(columnKey) (List<String>). Malformed or absent cells return the supplied fallback (Optional.empty(), defaultValue, or Collections.emptyList()).
  • Lenient Scalar Coercion: TableCell.LenientStringDeserializer accepts JSON strings, numbers, and booleans on value while rejecting non-scalar {} or [] tokens.
  • Live Reload, Fallback & Actuator: UPDATED lifecycle events refresh the injected List<TableRow> field in place; absent startup keys retain the field’s default list and DELETED events revert it to that baseline (ADR 0003). ConfigurationActuatorEndpoint exposes remoteType = "TABLE" in /actuator/aircommerceConfig (ADR 0010).
  1. During Spring Application Context initialization, ConfigurationValueInjector scans beans for @ConfigurationValue.
  2. Initial hardcoded values are extracted via reflection and stored in the ConfigurationFieldRegistry as immutable baselines.
  3. The library initiates a Feign HTTP request to the Configuration Service API to retrieve the latest configuration documents for the service’s namespace.
  4. 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.

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).

Showing 4 of 4 architecture decisions

None