This is a Spring Cloud microservice project for coupon management.
Test using Jetbrains Remote Development...
Below are the workable versions, and higher versions may need to do some double check to make things work together.
- java 8
- Spring Cloud Greenwich.SR6
- SpringBoot 2.1.10.RELEASE
- MySQL 8.0.32
- Redis 6.0
- Kafka 2.2.2
- coupon-eureka:
- coupon-gateway:
-
for shared code base, configuration, response, and exception handling across the project
-
- build coupon-template:
- generate coupon-code:
- clean expired coupon-template:
-
- fetch a user's coupon records:
- fetch a user's applicable coupons:
- user apply coupons:
- pre-calculate/use a coupon:
-
- calculate with coupons:
-
-
path cration:
Add other microservice controller's URL/path into permission module. It provides APIs to offload such management from developers to PM or operation teams.
fas
-
permission validation:
-
- boot up MySQL, and create db and tables
- boot up Redis:
redis-server
on a server, or run it in a docker container - boot up Kafka: run it on a server
- run zookeeper first
/kafka_directory/bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
- use
jpa
and check if zookeeper Java ps is ready - run kafka when zookeeper is ready
nohup /kafka_directory/bin/kafka-server-start.sh config/server.properties &
- run zookeeper first
- boot up Eureka: For Eureka server cluster deployment on one server node, run
mvn clean package -Dmaven.test.skip=true -U
to build jar, add items with format127.0.0.1 eureka-server1
in the /etc/hosts file (make sure that a microservice's application.yml has configuration like eureka: client: service-url: defaultZone: http://eureka-server1:8001/eureka/). Then runjava -jar coupon-eureka-1.0-SNAPSHOP.jar --spring.profiles.active=eureka-server1
to boot up 1st node, then boot up the rest. - boot up Zuul:
- install coupon-common: it needs to be installed to local .m2 directory so that other modules can use it
- navigate to coupon-common root direct and run
mvn clean install
to install it into local .m2. - start basic services: mysql, redis, and kafka
- package spring cloud services: run
mvn clean build -Dspring.active.profile=prod --skip-test=true
for coupon-eureka, coupon-gateway and run the jar files withjava -jar xx.jar
. - package business modules: package all the business microservices and run jar files respectively
-
-
- JPA is the standard for ORM, while Hibernate is an implementation. We write JPA interface and let AOP do the magic.
// define entity and PrimaryKey type, JPA will do the match and query. public interface CouponTemplateDao extends JpaRepository<CouponTemplate, Integer> { CouponTemplate findByName(String name); // params math method names respectivelv. e.g ByAvailable -> available, Expired -> expired List<CouponTemplate> findAllByAvailableAndExpired(Boolean available, Boolean expired); List<CouponTemplate> findAllByExpired(Boolean expired); }
- Entity's partArgsConstructor: we normally define ID as a PrimaryKey and created by db, not by entity constructor.
-
- All packages in different module should have the same name. Otherwise, Spring cannot scan and manage the beans in a different package than your working package.
- Version compatible: SpringCloud vs SpringBoot version matrix. MySQL and connector version
- enhance gateway with more filters: check by url to do validation, query result cache, etc
- custom Kafka pipeline: directly send KafkaMessage into MQ without manually serialize/deserialize ops.
- enhance validation
- request tracing
- in-memory db, redis, kafka for Unittest
- distributed logging ELK
- monitor module
- docker composer configuration
- front end