In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
Today, I will talk to you about how to use Apache ServiceComb for micro-service development, containerization, and elastic scaling, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.
As an architecture model in the emerging field, micro-service architecture has entered the product form, and has become a hot spot together with containerization and clustering. The relationship among micro-services, Docker and kubernetes, what kind of relationship between them, and what role they can play in the field of micro-services, often bring a little confusion to entry-level readers and users.
The following is a simple universal micro-service example, starting from business scenarios to micro-service architecture design, implementation, containerization, cluster deployment, stress testing, auto scaling, and resource control. End-to-end demonstrates the relationship between the three in the most straightforward way, which will bring readers a different and authentic conceptual experience and experience, and enhance their understanding of the series of concepts.
An example of universal microservice
In order to make it easier for readers to understand the functions of the ServiceComb micro-service framework and how to use it to quickly develop micro-services, it provides familiar examples to reduce the learning curve, increase interest and deepen understanding.
In this paper, we assume that we have set up a research company to handle complex mathematical operations and cutting-edge biotechnology research, and provide users with the following services:
Calculation of golden section series
The law of honeybee reproduction (calculating the number of ancestors of each drone / female)
But how can we provide these powerful computing power of the company to our consumers?
First of all, we use authentication services to ensure that the company's computing resources are not abused, while we provide Rest services for users to access. The following video shows the specific service verification invocation.
Business scenario
Let's first summarize and analyze the business scenario.
For the sustainable development of the company, we need to charge for the computing power consumed by users, so we employ doormen to authenticate users to prevent lawbreakers from getting in.
In order to provide sufficient computing power for the golden section, we need to hire the corresponding technicians.
In order to continuously study the law of honeybee reproduction, the company has established its own beehive, which needs corresponding beekeepers to carry out management research.
In order to balance the workload and time of technicians, beekeepers and doormen, we have set up a bulletin board mechanism for people who are currently free to publish their contact information, so that we can contact people with matching skills in time to serve incoming users.
Because of the high cost of computing power, we have archived the computing project so that when we have the same request in the future, we can directly query the project archive and save the company's computing cost.
In the face of the above complex scene, we hired a department manager to manage the company's members and facilities.
Finally, when the company is growing and the number of users is skyrocketing, we need to recruit more technicians, beekeepers, and doormen, so we have added human resources departments.
Company structure (system architecture)
Up to now, the business scene has been relatively clear, we draw the above job departments and facilities into the company organization chart.
Now that the organizational structure of the company is complete, let's start to set up the corresponding department.
Craftsman (Worker)
Because the mechanic is the simplest and the least dependent on the staff of other departments, we set up this department first.
Golden Section Computing Service
The main work of the technician provides the golden section series calculation service. When the user needs to know the nth golden section number, the technician calculates the value as quickly as possible and returns it to the user. We can simplify this work to the following mathematical equations:
Value = fibo (n)
Without considering the performance for the time being, we can quickly realize the calculation of the golden section series.
Interface FibonacciService {long term (int n);} @ Serviceclass FibonacciServiceImpl implements FibonacciService {@ Override public long term (int n) {if (n = = 0) {return 0;} else if (n = = 1) {return 1;} return term (n-1) + term (n-2);}} mechanic service endpoint
Now that the golden section quantity operation has been implemented, we need to provide the service to the user. First, we define the endpoint interface:
Public interface FibonacciEndpoint {long term (int n);}
Introduce ServiceComb dependencies:
Org.apache.servicecomb spring-boot-starter-provider
Next, we expose both the Restful and RPC endpoints of the golden section computing service:
@ RestSchema (schemaId = "fibonacciRestEndpoint") @ RequestMapping ("/ fibonacci") @ Controllerpublic class FibonacciRestEndpoint implements FibonacciEndpoint {private final FibonacciService fibonacciService; @ Autowired FibonacciRestEndpoint (FibonacciService fibonacciService) {this.fibonacciService = fibonacciService;} @ Override @ RequestMapping (value = "/ term", method = RequestMethod.GET) @ ResponseBody public long term (int n) {return fibonacciService.term (n);} @ RpcSchema (schemaId = "fibonacciRpcEndpoint") public class FibonacciRpcEndpoint implements FibonacciEndpoint {private final FibonacciService fibonacciService @ Autowired public FibonacciRpcEndpoint (FibonacciService fibonacciService) {this.fibonacciService = fibonacciService;} @ Override public long term (int n) {return fibonacciService.term (n);}}
When the two endpoints are annotated with @ RestSchema and @ RpcSchema here, ServiceComb automatically generates the corresponding service endpoint contract, configures the endpoint port according to the following microsevice.yaml, and registers the contract with the service with Service Center:
# all interconnected microservices must belong to an application wth the same IDAPPLICATION_ID: companyservice_description:# name of the declaring microservice name: worker version: 0.0.1# service center addresscse: service: registry: address: http://sc.servicecomb.io:30100 highway: address: 0.0.0.0:7070 rest: address: 0.0.0.0:8080
Finally, provide the mechanic service application startup entry and add the @ EnableServiceComb annotation to enable ServiceComb:
@ SpringBootApplication@EnableServiceCombpublic class WorkerApplication {public static void main (String [] args) {SpringApplication.run (WorkerApplication.class, args);}} notice Bar (Bulletin Board)
The bulletin board provides facilities to register contact information for doormen, technicians and beekeepers, and managers and beekeepers can check the contact information of the registrants through this facility to facilitate the provision and consumption of matching capacity.
Service Center provides contract and service registration, discovery, and verifies whether the contract of the provider and the consumer matches. We can download the compiled version and run it directly.
Beekeeper (Beekeeper)
Beekeepers study the law of honeybee reproduction and calculate the number of ancestors of each bee (drone / female). Because the law of honeybee reproduction is related to the golden section series, beekeepers also consume the computing services provided by technicians.
Studies have shown that drones (Drone) are born from unfertilized eggs and only mothers, while females (Queen) are hatched from fertilized eggs and have both a mother and a father.
Credit: Dave Cushman's website
Referring to the figure above, the number of ancestors of a certain generation of bees fits the model of the golden section series, so we can quickly implement the service function.
Research service on the law of bee reproduction
First of all, we define the golden sequence operation interface:
Public interface FibonacciCalculator {long term (int n);}
Next, define and implement the honeybee reproduction law research service:
Interface BeekeeperService {long ancestorsOfDroneAt (int generation); long ancestorsOfQueenAt (int generation);} class BeekeeperServiceImpl implements BeekeeperService {private final FibonacciCalculator fibonacciCalculator; BeekeeperServiceImpl (FibonacciCalculator fibonacciCalculator) {this.fibonacciCalculator = fibonacciCalculator;} @ Override public long ancestorsOfDroneAt (int generation) {if (generation)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.