Tutorial 4 : Backend Development
Backend Development
Undertake tutorials with tech stack Spring Java backend.
tip
For completing below tutorials:
While building, Select appropriate Project configuration. And Make use of EasyManage: Templates.
Tutorial 4-A
Create Microservice
Note: Create
emapi
project for order table
Create e-Commerce Order Microservice
MySQL table:
CREATE TABLE order (
order_id int(11) NOT NULL AUTO_INCREMENT,
customer_id int(11) NOT NULL,
product_id int(11) NOT NULL,
order_date DATE NULL,
order_quantity int(11) DEFAULT 0,
order_status varchar(50) NULL,
PRIMARY KEY (order_id)
);
- Customize
order
model with below:- Auto-generate orderId (order_id column)
- Use @GeneratedValue annotation to automatically generate the primary key value for @Id.
- Add validation for orderQuantity (order_quantity column) as below:
- Must have value (not null) and value must be positive non-zero.
- Min quantity: 1, Max Quantity: 5
- Use annotations
@NotNull
,@Positive
,@Min(1)
,@Max(5)
- Auto-generate orderId (order_id column)
Tutorial 4-B
Microservice Communication and Events
Note: Create separate/new
emapi
project for shipping tables and use new ports for APIs e.g. 9060/9050
Create e-Commerce Shipping Microservice
MySQL tables:
CREATE TABLE product_inventory (
product_id int(11) NOT NULL,
available_quantity int(11) DEFAULT 0,
PRIMARY KEY (product_id)
);
INSERT INTO product_inventory (product_id ,available_quantity)
VALUES (1,50),(2,30),(3,40);
CREATE TABLE shipping (
shipping_id int(11) NOT NULL AUTO_INCREMENT,
order_id int(11) NOT NULL AUTO_INCREMENT,
product_id int(11) NOT NULL,
shipping_quantity int(11) DEFAULT 0,
shipping_status varchar(50) NULL,
PRIMARY KEY (shipping_id)
);
- Then Order Microservice will communicate with Shipping Microservice for checking available product quantities before creating order.
Implement Event Distribution With kafka:
- Then Order Microservice will produce event
order_created
and Shipping Microservice will comsume this event and create a sihpping record.
Tutorial 4-C
Requirements for API Development
Select Project configurations for below in Builder Studio and Implement/Verify them in generated emapi
project:
Testing
- tests UT Unit Tests, IT Integration Tests
- Run Tests: Report Location
- Surefire Report for unit tests
- Failsafe Report for integration tests
Code Coverage - SonarQube
Generating Code Coverage Locally with JaCoCo, Sonar Scanner
- Run Jacoco (Coverage Module)
- Report Location
- Coverage Report
- Coverage Report : dbrest
- Coverage Report : dbgraphql
- Take-home Exercises
- Increase code coverage to 70-80%
- Add more UT, IT
- Migrate Integration Tests from JUnit to TestNG
- Increase code coverage to 70-80%
tests API Tests - TestNG, WebClient
- dbrestTest - Tests Run
- dbrestTest - Report Location
- dbrestTest - Report
- dbrestTest - Emailable Report
- dbgraphqlTest - Tests Run
- dbgraphqlTest - Report
- dbgraphqlTest - Emailable Report
- Aggregate Test report
Tutorial 4-D
Enterprise Requirements for APIs and Microservices
- Take-home Exercises : Implement Enterprise Requirements for below.
Security - OAuth2 with Keycloak
Redis cache
Logging - ELK stack
Integrating - Kafka, Kafka Streams
- Distributed Events Aggregation with Kafka Streams
DevOps - CI/CD - Jenkins
- DevOps CI/CD pipelines for build, verify, deploy - using Jenkins.
Tutorial 4-E
Advanced Self-Learning Topics
Take-home Exercises : Implement below.
Testing
- BDD (Behavior-Driven Development) with
- Serenity BDD, Cucumber