This is a generator that scaffold hybrid service which is on top of light-hybrid-4j and light-4j
frameworks. Hybrid framework contains a set of handlers to support RPC style of contract instead
of Restful to eliminate the complex transformation between model and URI and vice verse. Currently
we support JSON RPC only and binary RPC will be supported if there are requests. Another benefit
of hybrid framework is that services can be composed as a modular monolith and running within the
same JVM in the beginning and then split them into several JVM later on if load is getting higher.
It is very suitable for small and medium size business as you can start microservices without
the huge front end infrastructure investment.
As light-hybrid-4j is an RPC based framework, only HTTP POST method is used. Currently, only JSON based RPC is
implemented and binary formatted protocol will follow.
Here is an exmaple of schema that defines several services.
name is used in generated pom.xml for project name
version is used in generated pom.xml for project vesion
groupId is used in generated pom.xml for project groupId
artifactId is used in generated pom.xml for project artifactId
rootPackage is the root package name for your project and it will normally be your domain plug project name.
handlerPackage is the Java package for all generated handlers.
modelPackage is the Java package for all generated models or POJOs.
overwriteHandler controls if you want to overwrite handler when regenerate the same project into the same folder. If you only want to upgrade the framework to another minor version and don’t want to overwrite handlers, then set this property to false.
overwriteHandlerTest controls if you want to overwrite handler test cases.
httpPort is the http port number the server is listening to if it is enabled.
enableHttp is the flag to control if http is enabled or not.
httpsPort is the https port number the server is listening to if it is enabled.
enableHttps is the flag to control if https is enabled or not.
supportDb to control if db connection pool will be setup in service.yml and db dependencies are included in pom.xml
dbInfo section is the database connection pool configuration info.
supportH2ForTest is a flag to control if H2 code is included in the test server and H2 jar is included in pom.mxl
supportClient is a flag to control if client module is included in the generated project to call other services.
Java Command line
Before using the command line to generate the code, you need to check out the repo and build it.
I am using ~/networknt as workspace but it can be anywhere in your home.
git clone [email protected]:networknt/light-codegen.git
mvn clean install
This is a generator that scaffolds a service module that will be hosted on a light-hybrid-4j server
platform as a jar file. Multiple modules can be hosted on the same server if needed and they can
interact with each other through a module interface/contract defined by schema files. The generated
project cannot run directly as it’s only a small jar file without a main class. However its services are
enabled by placing the jar file into the classpath of the server. For multiple jar files, we recommend
creating a folder like /service or /lib within the class path of the server and having it contain all
necessary light-hybrid-4j services.
The following will generate a sample light-hybrid-4j service which exposes a hello-world endpoint.
Working directory: light-codegen