Light-codegen provides a generator to generate the 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.
The command side service will publish the event to event store to change the state of the domain object or entire system.
The query side service will subscribe the event from event store and return results only and does 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.
Being different from the 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 be like the following:
User can refer to todo-list example spec to build their own specification for eventuate based rest API generation.
used in generated pom.xml for project version
used in generated pom.xml for project version
used in generated pom.xml for project groupId
used in generated pom.xml for project artifactId
the root package name for your project and it will normally be your domain plug project name.
the Java package for all generated handlers.
the Java package for all generated models or POJOs
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.
the Java package for Eventuate command side component module; Normally we put commands definition and aggregation classes in this module.
the Java package for Eventuate query side component module; It includes query side DAO or repository service module.
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.
control if you want to overwrite handler test cases
controls if you want to overwrite generated models
controls if you want to overwrite generated eventuate modules, which include commnon module, command module and query module.
the port number of Http listener if enableHttp is true.
to specify if the server listens to http port. Http should only be enabled in dev.
the port number of Https listener if enableHttps is true.
to specify if the server listens to https port. Https should be used in any official environment for security reason.
to control if built-in service registry/discovery is used. Only necessary if running as standalone java -jar xxx.
to control if db connection pool will be setup in service.yml and db dependencies are included in pom.xml
section is the database connection pool configuration info.
if true, add H2 in pom.xml as test scope to support unit test with H2 database.
if true, add com.networknt.client module to pom.xml to support service to service call.
Here is an example of config.json for openapi generator.
To initialize the eventuate based the API service, the config value overwriteEventuateModule should be set as true.
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 the 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.