LIGHT

  • News
  • Docs
  • Community
  • Reddit
  • GitHub

Eventuate Generator

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.

Input

Model

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:

{
"command":
{
...
}
"query":
{
...
}
}

User can refer to todo-list example spec to build their own specification for eventuate based rest API generation.

Config

Field NameDescription
nameused in generated pom.xml for project version
versionused in generated pom.xml for project version
groupIDused in generated pom.xml for project groupId
artifactIdused in generated pom.xml for project artifactId
rootPackagethe root package name for your project and it will normally be your domain plug project name.
handlerPackagethe Java package for all generated handlers.
modelPackagethe Java package for all generated models or POJOs
eventuateEventPackagethe 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.
eventuateCommandPackagethe Java package for Eventuate command side component module; Normally we put commands definition and aggregation classes in this module.
eventuateQueryPackagethe Java package for Eventuate query side component module; It includes query side DAO or repository service module.
overwriteHandlercontrols 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.
overwriteHandlerTestcontrol if you want to overwrite handler test cases
overwriteModelcontrols if you want to overwrite generated models
overwriteEventuateModulecontrols if you want to overwrite generated eventuate modules, which include commnon module, command module and query module.
httpPortthe port number of Http listener if enableHttp is true.
enableHttpto specify if the server listens to http port. Http should only be enabled in dev.
httpsPortthe port number of Https listener if enableHttps is true.
enableHttpsto specify if the server listens to https port. Https should be used in any official environment for security reason.
enableRegistryto control if built-in service registry/discovery is used. Only necessary if running as standalone java -jar xxx.
supportDbto control if db connection pool will be setup in service.yml and db dependencies are included in pom.xml
dbInfosection is the database connection pool configuration info.
supportH2ForTestif true, add H2 in pom.xml as test scope to support unit test with H2 database.
supportClientif 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.

{
  "name": "todolist",
  "version": "1.0.0",
  "groupId": "com.networknt",
  "artifactId": "todolist",
  "rootPackage": "com.networknt.todolist.rest",
  "handlerPackage":"com.networknt.todolist.rest.handler",
  "modelPackage":"com.networknt.todolist.rest.model",
  "eventuateEventPackage":"com.networknt.todolist.event",
  "eventuateCommandPackage":"com.networknt.todolist.command",
  "eventuateQueryPackage":"com.networknt.todolist.query",
  "overwriteHandler": true,
  "overwriteHandlerTest": true,
  "overwriteModel": false,
  "overwriteEventuateModule": true,
  "httpPort": 8082,
  "enableHttp": true,
  "httpsPort": 8482,
  "enableHttps": true,
  "enableRegistry": false,
  "supportOracle": false,
  "supportMysql": true,
  "supportPostgresql": false,
  "supportH2ForTest": true,
  "supportClient": false,
  "dockerOrganization": "networknt"
}

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

For light-codegen eventuate generator, there is an example todo-list spec & config for light-codegen in model-config repo.

Let’s clone the project to your workspace as we will need it in the following steps.

Assume ~/networknt is the workspace root folder, but it can be anywhere in your home directory.

cd ~/networknt
git clone [email protected]:networknt/model-config.git

Usage

Java Command line

You can download or build the codegen-cli command line jar.

Using the example spec and config in model-config repo, generate eventuate based API todo-list.

Working directory: ~/networknt

cd ~/networknt
java -jar light-codegen/codegen-cli/target/codegen-cli.jar -f eventuate-rest -o /tmp/eventuate/todo-list -m model-config/rest/openapi/eventuate/todo-list/schema.json -c model-config/rest/openapi/eventuate/todo-list/config.json

After you run the above command, you can build and start the service:

cd /tmp/eventuate/todo-list
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.

Codegen Site

You can generate single project or multiple projects from the site https://codegen.lightapi.net with your model and config files.

  • About Light
    • Overview
    • Testimonials
    • What is Light
    • Features
    • Principles
    • Benefits
    • Roadmap
    • Community
    • Articles
    • Videos
    • License
    • Why Light Platform
  • Getting Started
    • Get Started Overview
    • Environment
    • Light Codegen Tool
    • Light Rest 4j
    • Light Tram 4j
    • Light Graphql 4j
    • Light Hybrid 4j
    • Light Eventuate 4j
    • Light Oauth2
    • Light Portal Service
    • Light Proxy Server
    • Light Router Server
    • Light Config Server
    • Light Saga 4j
    • Light Session 4j
    • Webserver
    • Websocket
    • Spring Boot Servlet
  • Architecture
    • Architecture Overview
    • API Category
    • API Gateway
    • Architecture Patterns
    • CQRS
    • Eco System
    • Event Sourcing
    • Fail Fast vs Fail Slow
    • Integration Patterns
    • JavaEE declining
    • Key Distribution
    • Microservices Architecture
    • Microservices Monitoring
    • Microservices Security
    • Microservices Traceability
    • Modular Monolith
    • Platform Ecosystem
    • Plugin Architecture
    • Scalability and Performance
    • Serverless
    • Service Collaboration
    • Service Mesh
    • SOA
    • Spring is bloated
    • Stages of API Adoption
    • Transaction Management
    • Microservices Cross-cutting Concerns Options
    • Service Mesh Plus
    • Service Discovery
  • Design
    • Design Overview
    • Design First vs Code First
    • Desgin Pattern
    • Service Evolution
    • Consumer Contract and Consumer Driven Contract
    • Handling Partial Failure
    • Idempotency
    • Server Life Cycle
    • Environment Segregation
    • Database
    • Decomposition Patterns
    • Http2
    • Test Driven
    • Multi-Tenancy
    • Why check token expiration
    • WebServices to Microservices
  • Cross-Cutting Concerns
    • Concerns Overview
  • API Styles
    • Light-4j for absolute performance
    • Style Overview
    • Distributed session on IMDG
    • Hybrid Serverless Modularized Monolithic
    • Kafka - Event Sourcing and CQRS
    • REST - Representational state transfer
    • Web Server with Light
    • Websocket with Light
    • Spring Boot Integration
    • Single Page Application
    • GraphQL - A query language for your API
    • Light IBM MQ
    • Light AWS Lambda
    • Chaos Monkey
  • Infrastructure Services
    • Service Overview
    • Light Proxy
    • Light Mesh
    • Light Router
    • Light Portal
    • Messaging Infrastructure
    • Centralized Logging
    • COVID-19
    • Light OAuth2
    • Metrics and Alerts
    • Config Server
    • Tokenization
    • Light Controller
  • Tool Chain
    • Tool Chain Overview
  • Utility Library
  • Service Consumer
    • Service Consumer
  • Development
    • Development Overview
  • Deployment
    • Deployment Overview
    • Frontend Backend
    • Linux Service
    • Windows Service
    • Install Eventuate on Windows
    • Secure API
    • Client vs light-router
    • Memory Limit
    • Deploy to Kubernetes
  • Benchmark
    • Benchmark Overview
  • Tutorial
    • Tutorial Overview
  • Troubleshooting
    • Troubleshoot
  • FAQ
    • FAQ Overview
  • Milestones
  • Contribute
    • Contribute to Light
    • Development
    • Documentation
    • Example
    • Tutorial
“Eventuate Generator” was last updated: July 5, 2021: fixes #275 checked and corrected grammar/spelling for majority of pages (#276) (b3bbb7b)
Improve this page
  • News
  • Docs
  • Community
  • Reddit
  • GitHub
  • About Light
  • Getting Started
  • Architecture
  • Design
  • Cross-Cutting Concerns
  • API Styles
  • Infrastructure Services
  • Tool Chain
  • Utility Library
  • Service Consumer
  • Development
  • Deployment
  • Benchmark
  • Tutorial
  • Troubleshooting
  • FAQ
  • Milestones
  • Contribute