The simplest microservice deployment and testing practice

Microservices are particularly suitable for projects with complex business and large development teams. Microservices can achieve the effect of breaking up into parts, simplifying individual services, and reducing communication costs. However, the performance of microservices is lower than that of single services, and there will also be data redundancy problems. You must combine your own conditions and do not blindly worship.
This article introduces a simple microservice technology architecture. Help everyone have a preliminary understanding of how to deploy and develop microservices.

A simple microservice architecture

The deployment diagram is as follows
The simplest microservice deployment and testing practice

nginx:

Unified external entrance, distribute requests to different microservices according to url, and distinguish different microservices with ip:port. It also directly handles the access of some static resources, which is a web server itself.

springboot+dubbo:

Spring boot is currently the most popular framework for developing web services (jsp, ejb, and ssh are too old). It is not necessarily related to microservices, but it can be combined with dubbo to develop microservices. The requirement is that the spring boot project should import dubbo .jar or use maven to import dubbo. Configure dubbo-application.xml, write the zookeeper service address port and the interface method that providers and consumers need to register.
To call a method of another microservice from one microservice, only need \@Autowired to register the object of the interface class and use the object to call the method. The troublesome point is that each microservice must have a consistent interface description java file for the same interface method. Using maven to manage the jar package describing the interface can effectively solve the problem of consistent interface.
Finally, click the jar package, and the java -jar ***.jar microservice is started.

zookeeper:

Springboot requires dubbo, and the most recommended service registration center for dubbo is zookeeper, which is equivalent to a bulletin board. Each microservice can see the interface methods of the providers and consumers registered above

DB:

MySQL Oracle等

repeat :

Cache session data, and other business data that needs to be cached

tomcat+dubbo-admin:

The dubbo management system is used to monitor and troubleshoot. It is deployed under tomcat. You can view the running status of each microservice on the browser to see whether a method can be called normally.

Points query business scenarios to help understand microservices.

The B service provides the function of checking the login status. The A service provides the function of querying account points.
When the user clicks to query points in the app, nginx sees that there are query points keywords in the url, and will send the request to the A service according to the configuration of nginx.conf, the app will send a sessionid to the A service, and the A service remotely calls the B service Check the login status of the interface, pass the sessionid to the interface, the B service interface is called, use the sessionid to check the user information in redis, if redis has the corresponding user information, the user information is returned, and the A service receives the return from the remote call interface User information userid, and then according to the user information to the database DB query points.
This is an example of two microservices working together to implement a business, using all the units in the architecture diagram. The requirements for querying the login status exist in each business, so there will be many microservices that need to remotely call the interface of the B service. At the same time, each microservice can be both a provider and a consumer.
The simplest microservice deployment and testing practice

Configure a complete set of microservice development environment under windows.

nginx

D:\Program Files\nginx-1.8.1>start nginx.exe
The simplest microservice deployment and testing practice

After success, the browser is as follows
The simplest microservice deployment and testing practice

MySQL

D:\Program Files\mysql-8.0.12-winx64\bin>mysqld --console
The simplest microservice deployment and testing practice

repeat

D:\Program Files\Redis-x64-3.0.504>redis-server.exe redis.windows.conf
picture I forgot to cut

zookeeper

Double-click zkServer.cmd
The simplest microservice deployment and testing practice
The simplest microservice deployment and testing practice

tomcat和dubbo-admindubbo-admin

You need to download it on github, and then compile dubbo-admin separately and play the war package. The war package is placed in the webapps directory of tomcat. When tomcat starts, the folder will be automatically decompressed, as shown below
The simplest microservice deployment and testing practice

The browser is as follows after successful execution of startup.bat in the tomcat/bin directory
The simplest microservice deployment and testing practice

Open http://127.0.0.1:8080/dubbo-admin-2.5.8/   (I got stuck when opening the page at first, but after deleting all the logs in tomcat/log, it was normal)
username root password root
The simplest microservice deployment and testing practice
The simplest microservice deployment and testing practice

No microservices have been started, so all items in the above figure are empty. Run two microservices in Intellij IDEA (java -jar in cmd can start the
microservice jar package, but it is not convenient to debug and modify the code). You can see that the dubbo management system can see two services, one is the provider and the other is the consumer By. You can view the name, status, and log inside, which is helpful for troubleshooting.
The simplest microservice deployment and testing practice
The simplest microservice deployment and testing practice
The simplest microservice deployment and testing practice

Test dubug

Enter the login url in the browser to see the login page opened.
The simplest microservice deployment and testing practice

At this point, the development and debugging environment of a microservice system is complete. If you only test the back-end service and don't care about the functions of the browser and app interface, you can use the postman tool to send the URL directly to the server to check whether the returned json data meets the expected requirements.

Guess you like

Origin blog.51cto.com/14947900/2539749