“This is the 14th day of my participation in the First Challenge 2022. For details: First Challenge 2022.”

Hello everyone, I’m Ah Q!

Last time we talked about the problems knife4j caused our project, then we looked at the Gateway document aggregation pattern, in this article we’ll talk about the centralized registration pattern!

Centralized registration mode

Okay, I made up the name, but I thought it was more graphic. The specific technical architecture is shown in the figure below:

The system flow is as follows:

  1. Each microservice starts fromnacos,eurekaWait for the registry to obtainswaggerRegistry service registration information, and then callswaggerThe interface to the registry willswaggerThe information is saved to the database
  2. swaggerRegistry integrationknife4jIs itself a separate microservice that connects to and manages the databaseswaggerThe document
  3. Users can access the Intranet onlyswaggerThe registry,swaggerThe registry is fetched from the databaseswaggerDocument information and passknife4jApply colours to a drawing

Note that the Swagger registry only deploys the development environment or the company LAN environment. Our company LAN can directly access the development environment.

The code design for centralized registration mode is as follows, with two separate projects

The project name function
swagger-spring-boot-starter The client component that the microservice client uses to encapsulate the component to scan the projectswaggerInformation and upload itswaggerThe registry
swagger-register-server swaggerRegistry, which receives uploads from microservice clientsswaggerThe information is saved to the database. When a user requests to view a document, it is fetched directly from the databaseswaggerThe document

I’ll leave you a question, so you can think about the difference between these two approaches. Before we get started, we need to know how swagger-UI works. Here we go!

Post off

Ah Q will continue to update the Java practice of the article, interested in the public account can pay attention to: AH Q said the code, also can come to the technical group to discuss the problem!