Code Monkey home page Code Monkey logo

ralphs-microservices's Introduction

microservice-examples

This is a collection of basic examples about how to implement a Microservice on different platforms. The examples can be used as templates for own projects on different environments:

Hello-World Example Jakarta EE 9

A Microservice is build in JDK 11 and based on Jakarta EE 9 and Microprofile 3.2. The project runs with Docker on Payara or Wildfy.

Hello-World Example Jakarta EE 8

A Microservice is build in JDK 1.8 and based on Jakarta EE 8 and Microprofile 3.2. The project runs with Docker on Payara or Wildfy.

Hello-World Example Spring Boot 2.6.2

A Microservice is build in JDK 11 and based Spring Boot 2.6.2. The project can be started form Java Main class BaseApplication or with the SpringBoot uber jar.

The Rest API

The Microservice proivdes 2 simple Rest API endpoints:

The Ping Service

The Ping resource just returns a ping message with a timestamp:

http://localhost:8080/api/ping

The Address Service

The Address resource is an example how to deal with POJOs in a Rest API method.

http://localhost:8080/api/data/address/123

The Service creates a simple Address Java Object and returns the object data requested in JSON or XML

Swagger API

All implementations include a Swagger OpenAPI documentation accessible from your web browser. The the project details how to access the Swagger API for different platforms.

Logging

All implementations use the standard java logger java.util.logging.Logger to print log messages to the server log file. So there is not extra logging framework needed.

Health Service

The Jakarta EE implementations also include a Health API example.

	http://localhost:8080/health

Inject Configuration Params via Environment variables

All implementations are including a configuration example.

The Ping Service reads in each request the Environment variable MAIL_HOST and prints out the value into the server log file. This is an example how you can externalize configuration to environment variables. For example in this way you can set different values for different environments.

Maven Archetype

You can also generate a Maven Archetype out from each of the projects to be used to create custom projects:

$ mvn archetype:create-from-project

This will generate a new archetype from the current project. Next navigate to target\generated-sources\archetype and run:

$ mvn install archetype:update-local-catalog

Now the new archetype is installed locally. You can create a new project now with:

$ cd my-project-folder	
$ mvn archetype:generate -DarchetypeCatalog=local

Choose the number of your generated project.

Or run:

$  mvn archetype:generate -DarchetypeCatalog=local -DarchetypeGroupId=com.rsoika  -DarchetypeArtifactId=hello-world-jakarta9-archetype

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.