Light-codegen provides a generator to generate eventuate base API based on OpenAPI 3.0 specification.
The eventuate based API is built based on light-eventuate-4j framework. light-eventuate-4j framework design eventuate microservice API based on CQRS (Command Query Responsibility Segregation) design pattern.
The service specification defined for Eventuate based API code generator should include the service definition for both CQRS command side service and query side service.
Command side service will publish event to event store to change the state of the domain object or entire system
Query side service will subscribe the event from event store and return results only and do not change the state of an object
In light-eventuate-4j framework generator, the model that drives code generation is the OpenAPI
specification which same as normal light-rest-4j API OpenAPI specification.
But different as normal light-rest-4j api OpenAPI specification, the eventuate based rest API Json format specification includes two services module definition (command service & query service)
The base Json format will like the following:
User can refer to todo-list example spec to build their own specification for eventuate based rest API generation.
Here is an example of config.json for openapi generator.
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.
eventuateEventPackage is the Java package for Eventuate common module which defined components could be shared by command service and query service; Normally we can put events objects and domain objects in this module.
eventuateCommandPackage is the Java package for Eventuate command side component module; Normally we put commands definition and aggregation classes in this module.
eventuateQueryPackage is the Java package for Eventuate query side component module; It includes query side DAO or repository service module.
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.
overwriteModel controls if you want to overwrite generated models.
overwriteEventuateModule controls if you want to overwrite generated eventuate modules, which include commnon module, command module and query module.
httpPort is the port number of Http listener if enableHttp is true.
enableHttp to specify if the server listens to http port. Http should only be enabled in dev.
httpsPort is the port number of Https listener if enableHttps is true.
enableHttps to specify if the server listens to https port. Https should be used in any official environment for security reason.
enableRegistry to control if built-in service registry/discovery is used. Only necessary if running as standalone java -jar xxx.
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 if true, add H2 in pom.xml as test scope to support unit test with H2 database.
supportClient if true, add com.networknt.client module to pom.xml to support service to service call.
For initialize the eventuate based the API service, the config value “overwriteEventuateModule” should be set as true.
The the light-codegen eventuate generator will generate the eventuate rest API project with the following modules:
– common module: Shared components module which will be used on both command side service module and query side service module. Normally, it includes events definition and data module for rest API
– command module: Eventuate command side component module; Normally we put commands definition and aggregation classes in this module.
– query module: Eventuate query side component module; It includes query side DAO or repository service module.
– command side service module: CQRS command side service module
– query side service module: CQRS query side service module
After you run the above command, you can build and start the service:
mvn clean install
Then user can start API developing the detail services from the generated project. For the detail development for the eventuate based API, please refer the todo-list example or account-transfer example code on the light-example-4j repo
The eventuate tutorial document includes the detail information about light-eventuate-4j framework and how to use it for eventuate based service API.
The service API is ready. We are working on the UI with a generation wizard.