Micro Services (reprint)

Programmers have a wife is tired after last finally explained to her what a Restful, this does not trouble again ...

Sunday morning, the sun shines on my face, I slowly wake up. I rolled over, I feel like less of something, slowly opened his eyes, "Hey, wife?"

Suddenly, I found the bed more than a piece of paper:

When you see this letter, I have been on the way back home, because I'm sure you know. If you do not understand, please turn to the back of the letter.

I look ignorant force, the paper turned over:

Well, how can you not know the reason, you turned it over just want to confirm that I have found is not a secret that only you, I'll tell you.

On your desk, there is a book called "micro-service design", although I am a girl, but I know that "service" is what activities did not think you stood a good programmer is not actually start a "service "you and pimps old age What is the difference?

Book I turned a bit, you want to see this "micro-service" is how a "micro" approach, Well, you pretty savvy programmers, look books are encrypted? Do not think I do not know what is the code, your programmer is a universal language. God knows there say something.

Anyway, since you chose this path, it will blame me unjust, good-bye. No, never seen. - you are disappointed Shizuka

I gradually slow to God, have mixed feelings, a myriad of thoughts, deep thought for a moment, pick up the phone, sent her a message:

"Four in the afternoon, the old place, explain to you what is micro-services."

Waltz department stores and supermarkets

I arrived fifteen minutes ahead of the cafe. Approaching four o'clock, I started looking at the door, 59 minutes 49 seconds, a familiar figure walked in, wearing sunglasses, dressed in scarf, she is.

"Waiter, a cheesecake, two cups of latte, thank you," I said to the waiter.

"Well, what do you want to explain?"

"Ah, first of all, I assure you, I'm watching" micro-service ", that is definitely not what you think" service "and"

"what is that?"

"To take the time to explain this, let's have some cake, and then slowly and you will be interpreted"

After a while, almost eat cake. "See that house across the Waltz supermarkets that?" I pointed out the window Waltz supermarket, he said to his wife.

I gradually slow to God, have mixed feelings, a myriad of thoughts, deep thought for a moment, pick up the phone, sent her a message:

"Four in the afternoon, the old place, explain to you what is micro-services."

Waltz department stores and supermarkets

I arrived fifteen minutes ahead of the cafe. Approaching four o'clock, I started looking at the door, 59 minutes 49 seconds, a familiar figure walked in, wearing sunglasses, dressed in scarf, she is.

"Waiter, a cheesecake, two cups of latte, thank you," I said to the waiter.

"Well, what do you want to explain?"

"Ah, first of all, I assure you, I'm watching" micro-service ", that is definitely not what you think" service "and"

"what is that?"

"To take the time to explain this, let's have some cake, and then slowly and you will be interpreted"

After a while, almost eat cake. "See that house across the Waltz supermarkets that?" I pointed out the window Waltz supermarket, he said to his wife.

 
 

"Ok?"

"It has everything, clothes, food, stationery, furniture, appliances, everything, and no matter where you go to a chain, the store is exactly the same pattern. Precisely because of this, this poses a problem. "

"What's wrong? I think this is very good ah, the customer went there looking for anything too are looking forward to."

"First, they sell different items  will affect the compartments between each other  , you see, on the first floor are jewelry stores and appliance stores, if you want jewelry store decoration, noise and dust during the renovation, will inevitably affect the electronics store; Also Yes, if due to the negligence of an electronics store employees, triggered a fire, next to the jewelry store you are not also be involved? "

"You big mouth ..."

"Ha ha, if it is said. In addition to this, there is a problem, I test you, our city has several supermarkets Waltz?"

"I think about it, it seems this one?"

"Yes, only in the West opened a shop here. This time marketing director found that live mostly in the Eastern upper class, their demand for jewelry is relatively large, this time to how to do?"

"Then in the Eastern Waltz also open a department store supermarket Luo."

"Ah, I can only be so, but demand for other things not many residents of the eastern, and they want every Waltz supermarket stores selling things are the same, so they had to open a branch in the East, not only sell jewelry, also sell food, clothes, and other things. "

"It's quite a waste it,  in order to meet the demand for jewelry, but also opened a department store supermarket  .", Wife thoughtfully.

"Indeed, everything, everything selling department store supermarket is too  heavy  , and this has been the" micro-services ""

"Oh? Finally talk about micro-served? Hum."

Waltz shop

"You see, if we Waltz supermarkets,  split into a number of shops selling different products  , such as selling jewelry Wolff, sell furniture Wall home, selling food there is good selling clothes Wall Wall clothing, which provide different services shop, located in various parts of the city, so they do not affect each other between the East Wall home Erxiang engaged in the decoration, the Sanxiang Wolff will not be affected.; Three Tunnels Wolff fire, and also Erxiang Wall home safe and sound. "

"Soga, turned out to be such a micro-services," his wife said with a smile.

"Not only that, now, we find a large population of Eastern demand for jewelry, then we in the East  to open several Wolff , and in the West, where more middle class, we will open several Wall good."

 
 

"Wow, it would appear, micro service to become Waltz  compact  a lot! Which big local demand for certain services in place corresponding to open several shops selling the kind of service just fine."

Waltz Shop

"It seems that micro-services is to become a department store each store Well, say this thing is so thick a book As for what?", My wife is a very curious girl.

"Well, of course not only these micro-services, we are now just a department store split into individual shops, but for  how to manage these shops  , we are not ready."

"Oh? What there is also a doorway?"

"Of course, do not forget, but there Waltz shop. Before or department stores when customers buy from the Internet if there is a piece of clothing, then removed the dress from supermarkets and warehouse, send to the customer like the past; now, each one selling clothes Wall clothes has its own warehouse, after the customer orders the staff to know how the customer which of several areas where Wal clothes from Wal which clothes? delivery of it? "

"Yo West, there is this problem. That  Waltz headquarters in which they must know what place to open branches, right  ?"

"Yes, this time the shop staff will find out from where the head office, customer shipping address areas where Wal what clothes home, the next step is from the Wall clothes shop, choose one, send courier to the customer in the past . "

"Recent customer to choose from that one thousand million."

"Ha, that in case there are two Eastern Wall clothes, a residential area close to, one near the business district, and the customer addresses are usually written harvest write their own home?"

"So ... it is close to residential areas of Volta clothing will receive a lot of orders, often to keep the purchase, the business district and close to the house, nothing orders, is not it?", My wife looked at me with wide eyes.

"Yes! That's the problem, so the staff will shop in an area of Wall clothing, were  in turn shipped  operations, such as this one is near a residential area of this shipment, the next time, let's close Wall clothing business district of shipments. "

"Rope!"

"Computer terminology, is  LoadBalancing  , load balancing"

"Oh, little pull these terms, I only know that New Balance"

"Ha ha, how, micro service is not as you think of it, of course, in the field of economics, there are many factors to consider, in real life Waltz is still a big department stores, naturally has its own reason the application of micro services mainly in the computer field more pure, that is, code that "what you see

"Well, I see those big head, go, take me to her parents luggage"

“……”

Words for programmers

Use the vernacular, to tell his wife understand the ins and outs of micro-services, of course, there are some things I still want to say, or henpecked listening look ignorant force, did not give her to say:

1, micro-speaking service, we have the  single application  talk (Monolithic).

The so-called single application, like department stores and supermarkets Waltz beginning, as all the code of business all together. Naturally, this is very appropriate for small projects, but the project once the big up more than one business, this monomer will  swell  , and the expanded single application There are two major drawbacks:

Indeed affect the whole body  . I changed a business line of code, we need to restart the entire application monomer, which is obviously not unreasonable. Like jewelry store decoration affect the electrical shop next, affecting the jewelry store when the fire as electrical shop.

Can only expand horizontally, you can not scale up  . For single applications, if you find a service request volume is very large, it is impossible to expand the business alone, can only copy the entire single application, and then deploy an environment to achieve the cluster.

Because of these monomers application has defects, it has a micro-services. The difference between the monomer and micro service applications, this can be explained in FIG Martin Fowler:

 
 

2, although micro-services architecture brings advantages, but it also introduces  complexity  . We may not use some of the components, to solve the problems caused by the complexity of the technology after improving:

服务注册中心 :一个服务可以有多个 实例 ,那么我们在向一个服务发出请求的时候,怎么知道这个服务有哪些实例呢?为了减少手工维护的麻烦,我们需要服务注册中心。每个服务实例在启动时,向注册中心注册自己的IP地址等信息。这样,服务在调用别的服务的接口时,就可以通过注册中心,查询到其他服务的实例,向实例发起请求。沃尔兹总店就是起到注册中心的作用。

负载均衡 :由于一个服务可以有多个实例,所以不管是来自外部客户端的请求,还是微服务系统内部服务之间发起的请求,都需要引入负载均衡的机制,来发挥多实例集群的作用。有的书也称这两种负载均衡为 服务器端负载均衡 和 客户端负载均衡 ,各自具有代表性意义的实现分别是Nginx和Ribbon。

API Gateway :一个外部请求过来之后,我们需要知道这个请求是发给哪个服务的,也就是我们需要一个 请求路由 的功能,比如/cm/*的请求,要发给客户管理服务,/om/*的请求,要发给订单管理服务。另外,不是所有请求都可以被我们系统处理的,我们需要判断这个请求是否携带一些必要的鉴权信息,并对其进行鉴权,也就是 请求过滤 的功能。而API Gateway,就是起到了这两个功能,它就像 整个微服务系统的门面 ,所有请求,都要先经过它的处理,才会转发到对应的服务。

……

 
 

Message bus and message-driven, there are many mechanisms, distributed configuration such as configuration management center for each of the service, a message service communication between the various components of the micro-derived service system (the above figure Message Queue) and the like, here I do not list them. This article just want a more interesting way, so that we have a preliminary understanding of the micro-services. Like learning to design mode, if go directly to the Gang of Four "Design Patterns - Elements of Reusable Object-Oriented Software", perhaps a lot of people do not go to school to learn half, and if the first look at "Head First Design Patterns" then go to the front of the book, maybe you will find a lot easier.

Sources micro services have a better understanding of what this micro-service design patterns, and Unix as well as  Conway's law  relationship;

See how the impact of micro-services software development  organization  , in fact, is Conway's law;

See Martin Fowler summarizes several principles of design of micro-service system;

If you want to have a further understanding of the micro-service, I recommend a side exchange study group: 685 167 672  which will share some senior architect video recording: There are Spring, MyBatis, Netty source code analysis, high concurrency, high performance, distributed , the principle of micro-services architecture, JVM performance optimization of these knowledge necessary to become an architect. Also receive free learning resources, currently benefited:

 
 

Architecture kind of thing, and design patterns are very similar, both solutions for a certain type of problem. And design patterns, each architecture has its advantages, of course, also have drawbacks. Why use this architecture only to find out, not what will happen, what will happen with the, know these know why, in order to use flexible architecture, take advantage of the architecture of the actual project.



Author: United States of impressive
link: https: //www.jianshu.com/p/a02b37c651ea
Source: Jane book
Jane book copyright reserved by the authors, are reproduced in any form, please contact the author to obtain authorization and indicate the source.

Guess you like

Origin www.cnblogs.com/lovleo/p/11257342.html