Code Monkey home page Code Monkey logo

city-tasks-spring-boot-oauth2's Introduction

Spring Boot Native/Reactive Microservice with OAuth2 and Quartz.

  • Author: Andres Solorzano.
  • Level: Advanced.
  • Technologies: Java 17, Spring Boot 3, Spring Native, Spring WebFlux, Spring OAuth2, Quartz, Flyway, Testcontainers, Postgres, DynamoDB and Docker Compose.

You can read the full article on my Medium Blog for more details.

Description.

This project uses the Spring Boot Framework to manage Quartz Jobs in a Spring Native microservice with the use of reactive programing using Spring WebFlux. The Quartz library is configured for clustered environments, so its needs the help of Postgres database to manage the cron Jobs execution. When a Job is executed, the calling method retrieves the Device item from DynamoDB to change its state. To perform these activities, the users must be logged into the OIDC Service that its deployed using the AWS Cognito service. All test cases using the TDD methodology from the beginning of the development phase, and only Integration Tests are executed with the support of Testcontainers because Unit Testing does not cover real world scenarios. This project also uses Docker Compose to deploy a local cluster alongside the other required services by the Spring Boot application.

Running using Docker Compose.

Only need to execute the following command from the project's root folder:

docker compose up --build

Getting Device items from DynamoDB on LocalStack.

Execute the following command:

aws dynamodb scan         \
  --table-name Devices    \
  --endpoint-url http://localhost:4566

Running using the Native Executable.

Use this option if you want to explore more features such as running your tests in a native image. IMPORTANT: The GraalVM native-image compiler should be installed and configured on your machine.

Deploy the required services using Docker Compose command:

docker compose up tasks-postgres tasks-localstack

Open a new terminal window and export the following environment variables:

export CITY_TASKS_DB_CLUSTER_SECRET='{"dbClusterIdentifier":"hiperium-city-tasks-db-cluster","password":"postgres123","dbname":"CityTasksDB","engine":"postgres","port":5432,"host":"localhost","username":"postgres"}'
export CITY_IDP_ENDPOINT='https://cognito-idp.us-east-1.amazonaws.com/<cognito_user_pool_id>'
export CITY_TASKS_TIME_ZONE_ID='-05:00'
export AWS_DEFAULT_REGION='ap-southeast-2'
export AWS_ACCESS_KEY_ID='DUMMY'
export AWS_SECRET_ACCESS_KEY='DUMMY'
export AWS_ENDPOINT_OVERRIDE='http://localhost:4566'

Then, create and run the native executable from the project's root directory:

$ ./mvnw clean native:compile -Pnative spring-boot:run

Reference Documentation.

For further reference, please consider the following sections:

Guides

The following guides illustrate how to use some features concretely:

Additional Links

These additional references should also help you:

GraalVM Native Support

This project has been configured to let you generate either a lightweight container or a native executable. It is also possible to run your tests in a native image.

Lightweight Container with Cloud Native Buildpacks

If you're already familiar with Spring Boot container images support, this is the easiest way to get started. Docker should be installed and configured on your machine prior to creating the image.

To create the image, run the following goal:

$ ./mvnw spring-boot:build-image -Pnative

Then, you can run the app like any other container:

$ docker run --rm city-tasks-spring-boot-oauth2:1.4.0

Executable with Native Build Tools

Use this option if you want to explore more options such as running your tests in a native image. The GraalVM native-image compiler should be installed and configured on your machine.

NOTE: GraalVM 22.3+ is required.

To create the executable, run the following goal:

$ ./mvnw native:compile -Pnative

Then, you can run the app as follows:

$ target/city-tasks-spring-boot-oauth2

You can also run your existing tests suite in a native image. This is an efficient way to validate the compatibility of your application.

To run your existing tests in a native image, run the following goal:

$ ./mvnw test -PnativeTest

city-tasks-spring-boot-oauth2's People

Watchers

Andres Solorzano avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.