Starting with examples is an excellent way to learn how to use each framework. Some of the examples have a corresponding tutorial so that you can follow them to rebuild the examples step by step.
Most examples are in light-example-4j repository in the networknt organization on github.com; however, there are some other examples scattered in other organizations or repositories.
Every example has a README.md to clearly state the purpose of the example and how to build and test it.
It is an example to show you how to use undertow routing handler. It opens the door to customize it and put your handlers in front of common handlers provided. This is a very low-level implementation on top of the light-4j framework.
The source code repo can be found at routing repository
Restful Database Access
There are three databases (Mysql, Postgres and Oracle) are used in this example and you can switch database with just configuration change in service.yml
The example shows:
- How to use HikariCP for JDBC connection pool.
- How to initialize database connection pool and plug it into light-4j startup hooks.
- How to dockerize light-4j application.
- How to compose databases with light-4j application so that you can start all servers together.
- How to performance test API application with wrk.
- Postgres performs better than mysql on my i5 desktop.
Techempower Performance Benchmark
We have submitted benchmark implementations to Techempower to compare light-4j with other frameworks on the market. The source code can be found in techempower repo and it is very good example on how to build high performance services including database access. The benchmark result can be found at techempower benchmark
There are several example applications that have multiple microserivces and they can be found in https://github.com/networknt/light-example-4j/tree/master/rest
These examples will show you:
- How to build microservices
- How to do API to API call with light-4j client component
- How to protect API with JWT token with scopes
- How to performance test APIs with wrk
- How to centralize logs with ELK
- How to collect metrics for each services
- How to deployed with Kubernetes
Microservices Chain Pattern - Swagger
In this example, there are four services chained together. A calls B, B calls C and C calls D in a chain pattern.
Microservices Branch Pattern
Microservices Aggregate Pattern - OpenAPI
This example can be found at /rest/openapi/ms_aggregate and you can use the above chain tutorial Quick Start link to understand how to run it as they are executed similarly. For a step-by-step tutorial you can visit aggregate tutorial.
light-4j and other related light-*-4j frameworks are some of the fastest frameworks to build microservices on the market in different styles. There are several examples that show developers how to implement high performance microservices.
There is a benchmark repository within networknt organization to compare all popular microservices frameworks on the market. The test is done on a desktop computer and focus on the raw throughput and latency of each framework. There might be more test cases added to the suite in the future though.
TechEmpower maintains a benchmark to compare all web frameworks and the source code can be found at techempower repo. The result can be found at techempower benchmark. We submitted our tests but there are still a lot of room to optimize the result especially the multiple database query and multiple database updates.