This repository shows how to natively extend Quarkus with a custom ConfigSource to use AWS AppConfig values when injecting config properties with @ConfigProperty.

Overview

Using AWS AppConfig in a custom MicroProfile ConfigSource

This repository shows how to natively extend Quarkus with a custom ConfigSource to use AWS AppConfig values when injecting config properties with @ConfigProperty.

This means that a developer can reference AppConfig properties like this:

@ConfigProperty(name = "myProp")
String myPropValue;

The demonstrated approach has several benefits:

  • The existing standard for injecting configuration in Quarkus can be used directly with AppConfig.
  • Configuration fetched from AppConfig has a configurable precedence. It can be used to e.g. override selected properties of the packaged application.properties file.
  • AppConfig access code is centralized within the application behind a standardized interface which makes the application easier to port.

How it works

To achieve this we create a class which implements org.eclipse.microprofile.config.spi.ConfigSource and register this clas in META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource. In the implementation of the class we periodically pull for new ConfigurationVersions using the AWS SDK for Java v2. If we receive a new configuration, the new configuration is read and the new values to properties are applied.

Navigate to AwsAppConfigSource.java learn what each overridden method accomplishes in context of the actual code.

Important: The RESTEasy implementation used by Quarkus scopes the lifecycle of JAX-RS resource classes (those annotated with @Path) to application scoped instead of the default request scoped outlined in the JAX-RS spec. This would effectively prevent us from rolling out new config values and directly use them in a running Quarkus application, as the resource class s only instantiated once. To circumvent this we wrap our ConfigProperty variable in a javax.inject.Provider and call javax.inject.Provider#get() each time to fetch the current, up-to-date value as stored in the ConfigSource.

The sample use case

Create an AWS AppConfig sample environment. Testing works best with the predefined environment in the cdk folder. A README.md for setting up the environment is included.

Testing the example

Firstly, setup the AWS AppConfig test environment from the CDK app. This is required as Quarkus will execute the ConfigSource code during build augmentation. Next ensure you have your local environment configured with a AWS credentials which allow interactions with AWS AppConfig.

Run the application locally:

./mvnw clean package
java -jar target/appconfig-quarkus-1.0-SNAPSHOT.jar 

You will see rather verbose log output which enables you to inspect what the sample application is doing.

Test drive the API endpoint:

curl localhost:8080/loan/annuity -d '{"amountInEur":1000, "durationInYears":1}' -H "Content-Type: application/json" 
# => {"annuity":1150.0000000000007}

Now update the configuration in AppConfig by updating the CDK app. In file cdk/lib/app-config-stack.ts change line 33 from

// Change this line and run 'cdk deploy' to update the config
content: initialConfigContent,

to

// Change this line and run 'cdk deploy' to update the config
content: updatedConfigContent,

and redeploy.

Observe over the next minute how AppConfig rolls out the change to the smaple app — this should not take longer than 2 intervals of 30 seconds in which the sample application checks for new configuration versios.

Test drive the API endpoint again and observe the new config value being used:

curl localhost:8080/loan/annuity -d '{"amountInEur":1000, "durationInYears":1}' -H "Content-Type: application/json" 
# => {"annuity":1009.9999999999991}%    

Contributions

To contribute with improvements and bug fixes, see CONTRIBUTING.

Security

See CONTRIBUTING for more information.

License

This library is licensed under the MIT-0 License. See the LICENSE file.

You might also like...

This sample shows how to implement two-way text chat over Bluetooth between two Android devices, using all the fundamental Bluetooth API capabilities.

This sample shows how to implement two-way text chat over Bluetooth between two Android devices, using all the fundamental Bluetooth API capabilities.

Zenitsu-Bluetooth Chat Application This sample shows how to implement two-way text chat over Bluetooth between two Android devices, using all the fund

Jan 16, 2022

Shows Image you select on Top of every Window by holding the button you choose

ImageOnTop What it does? Shows Image you select on Top of every Window by holding the button you choose. How to use it? Press a keyboard key you want

Jan 23, 2022

This project shows how to configure basic auth to secure our rest API and basic transaction on Data JPA

This project shows how to configure basic auth to secure our rest API and basic transaction on Data JPA

Basic Atuthentication Spring Boot Data JPA, MySQL This project shows how to configure basic auth to secure our rest API and basic transaction on Data

Feb 10, 2022

🍿 Movies and TV Shows streaming App powered by TMDb

🍿 Movies and TV Shows streaming App powered by TMDb

Cineapp A Movie / TV-Show streaming app with elegant UI Implementations The Movie Database (TMDb) Room Database Retrofit - for networking Glide - for

Dec 1, 2022

Android Application for a user’s favorite Movies, TV shows and Anime while keeping up to date with the latest releases.

MovieDroid Native Android Application for organized and categorized list of a user’s favorite movies and TV shows while keeping up to date with the la

Dec 26, 2022

A simple quarkus app with hibernate as ORM, used to show the features of Hibernate Search

beer-manager-hibernate-search Project This project uses Quarkus, the Supersonic Subatomic Java Framework. If you want to learn more about Quarkus, ple

Jan 6, 2022

Quarkus: Supersonic Subatomic Java.

Quarkus: Supersonic Subatomic Java.

Quarkus - Supersonic Subatomic Java Quarkus is a Cloud Native, (Linux) Container First framework for writing Java applications. Container First: Minim

Jan 3, 2023

An estate management api based on the hexagonal architecture, built on top of Quarkus

An estate management api based on the hexagonal architecture, built on top of Quarkus

Mar 30, 2022

Curso da Stack Quarkus - Alura

bitcoin Project This project uses Quarkus, the Supersonic Subatomic Java Framework. If you want to learn more about Quarkus, please visit its website:

Oct 29, 2021
Comments
  • Enhancements

    Enhancements

    Description of changes: This PR delivers suggested optimizations and clarifications.

    By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

    opened by julicjung 0
  • Various code optimizations

    Various code optimizations

    Description of changes:

    • Implement AutoCloseable
    • Add NPE check
    • Switch to ObjectMapper-based JSON unmarshal
    • Use friendly names for startConfigurationSession
    • Remove the optional polling constraint

    By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

    opened by julicjung 0
  • Upgrade to new dataplane API

    Upgrade to new dataplane API

    This PR upgrades the sample to use the new data plane API for fetching config. In addition it bumps versions of dependencies.

    By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

    opened by julicjung 0
  • Contribute initial sample code

    Contribute initial sample code

    Description of changes:

    • The initial sample code

    By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

    opened by julicjung 0
Owner
AWS Samples
AWS Samples
Render After Effects animations natively on Android and iOS, Web, and React Native

Lottie for Android, iOS, React Native, Web, and Windows Lottie is a mobile library for Android and iOS that parses Adobe After Effects animations expo

Airbnb 33.5k Jan 3, 2023
Demo microservice architecture with Spring ,Spring Cloud Gateway , Spring Cloud config server , Eureuka , keycloak and Docker.

spring-microservice Demo microservice architecture with Spring ,Spring Cloud Gateway , Spring Cloud config server , Eureuka , keycloak and Docker. Arc

null 4 Sep 13, 2022
Config files for my GitHub profile.

- Board: Board function plays the most role in all classes of this Project ROLES: + initBoard(): used to display the score, the state of

dtr_thuann 9 Dec 30, 2022
backend for a sharing app using SpringBoot, Redis, MySQL, and AWS S3.

moments_v2_backend (Work In Progress) backend for a sharing app using SpringBoot, Redis, MySQL, and AWS S3. This is the second version of my project S

Haiming Sun 53 Dec 26, 2022
AWS SaaS Boost

AWS SaaS Boost Overview AWS SaaS Boost provides organizations with ready-to-use core software elements for successfully running SaaS workloads in the

Amazon Web Services - Labs 839 Dec 27, 2022
An example project showing how to enable tiered compilation on a Java AWS Lambda function.

AWS Lambda Tiered Compilation Sample Getting started Download or clone the repository. To install prerequisite software: Install AWS CDK Install Apach

AWS Samples 18 Dec 13, 2022
SpringBoot service to pick up CAN messages retransmitted by CANBridge and extract certain values for reporting/monitoring/alerting via DataDog

SpringBoot service to pick up CAN messages retransmitted by CANBridge and extract certain values for reporting/monitoring/alerting via DataDog

Grumpy Cricket 2 Mar 12, 2022
A lightweight and extensible library to resolve application properties from various external sources.

Externalized Properties A lightweight and extensible library to resolve application properties from various external sources. Twelve Factor Methodolog

Joel Jeremy Marquez 20 Nov 29, 2022
QuickPerf is a testing library for Java to quickly evaluate and improve some performance-related properties

QuickPerf is a testing library for Java to quickly evaluate and improve some performance-related properties quickperf.io ?? Documentation Annotations

null 365 Dec 15, 2022
A lightweight and extensible library to resolve application properties from various external sources.

Externalized Properties A lightweight and extensible library to resolve application properties from various external sources. Twelve Factor Methodolog

Joel Jeremy Marquez 20 Nov 29, 2022