Introduction to modular project

Time:2021-10-16

modular

Project introduction

In a simple multi module project, messages are transmitted between modules through Kafka, using MySQL as temporary storage, redis as cache and mongodb as final data storage.
Project code acquisition:https://github.com/pysasuke/m…

Project structure

  • Modular common

    • Modular common base (simple common class)
    • Modular common database (MySQL related modules)
    • Modular common Kafka (Kafka related modules)
    • Modular common Mongo (mongodb related modules)
    • Modular common redis (redis related modules)
  • Modular handler (request processing module)
  • Modular first (Part I service module)
  • Modular second (Part II service module)
  • Modular third (Part III service module)
  • Modular exhandler (exception data processing module) (compensation mechanism)

Basic process

Because it is only a demo, only first, second and third simply refer to specific services, and the third service is the final service. The handler also uses manually constructed data

  • Request initiation
  • After passing through the handler module

    • Write a piece of data to MySQL
    • Write a piece of data to redis
    • Send a message to Kafka
  • After the first module receives the message sent by the handler module

    • Get the corresponding data from redis and verify it
    • Modify MySQL data after success
    • Modify redis data
    • Send a message to Kafka
  • After the second module receives the message sent by the first module

    • Get the corresponding data from redis and verify it
    • Modify MySQL data after success
    • Modify redis data
    • Send a message to Kafka
  • After the third module receives the message sent by the second module

    • Get the corresponding data from redis and verify it
    • Write a piece of data to mongodb after success
    • Delete redis data
    • Delete MySQL data
  • The exhandler module is a compensation mechanism

    • Handle the error data left in MySQL according to certain policies (normally, all data will be transferred to mongodb)

Project start

  • Execute update.sql in deploy to create the record table
  • Replace the relevant parameters in the application.properties configuration file in modular common database with their own MySQL parameters
  • Replace the relevant parameters in the application.properties configuration file in modular common redis with their own redis parameters
  • Replace the relevant parameters in the application.properties configuration file in modular common Mongo with their own mongodb parameters
  • Modify bootstrap in kafkaconstants class in modular common base_ The servers constant is its own Kafka address (because it is only a demo, it is not made into a configuration file)
  • Start related services

    • Normal process

      • Modular handler (request processing module)
      • Modular first (Part I service module)
      • Modular second (Part II service module)
      • Modular third (Part III service module)
    • Compensation mechanism

      • Modular exhandler (exception data processing module)

Result prediction

  • Modular first: output first service complete
  • Modular second: output second service complete
  • Modular third: output third service complete
  • A piece of data was written in mongodb

Recommended Today

Swift advanced (XV) extension

The extension in swift is somewhat similar to the category in OC Extension can beenumeration、structural morphology、class、agreementAdd new features□ you can add methods, calculation attributes, subscripts, (convenient) initializers, nested types, protocols, etc What extensions can’t do:□ original functions cannot be overwritten□ you cannot add storage attributes or add attribute observers to existing attributes□ cannot add parent […]