In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
About 2.Dubbo 2.1What is dubbo
Dubbo is a high-performance, lightweight open source Java RPC framework that provides three core capabilities: interface-oriented remote method invocation, intelligent fault tolerance and load balancing, and automatic service registration and discovery.
2.2 flowchart
Provider: the provider of the exposed service. Consumer: the service consumer that invokes the remote service. Registry: the registry for service registration and discovery. Monitor: the monitoring center that calculates the call time and call time of the service. Container: the service running container. 3. Specific implementation of 3.1 protocol selection
Connection number connection mode transport protocol serialization applicable scenario dubbo single connection long connection TCPNIO asynchronous transmission Hessian binary serialization incoming and outgoing parameter packets are small, the number of consumers is larger than the number of providers, a single consumer can not fill the provider general remote service method calls rmi multi-connection short connection TCP synchronous transmission Java standard binary serialization incoming and outgoing parameter packet size mix There are about the same number of consumers and providers, and they can send documents. Conventional remote service method invocation, interoperate with native RMI services, hessian multi-connection short connection HTTP synchronous transmission Hessian binary serialization incoming and outgoing parameter packets are larger, there are more providers than consumers, providers are under great pressure, and files can be transferred. Page transfer, file transfer, or interoperability with native hessian services
Http multi-connection short connection HTTP synchronous transmission form serialization incoming and outgoing parameters packet size mixed, the number of providers than consumers, can be viewed by the browser, the available form or URL input parameters need to be used by both the application and browser JS services.
Rest multi-connection short connection HTTP synchronous transfer form serialization is the same as http, suitable for services that are more in line with the rest specification and how http3.2 references services
At present, there are two schemes for referencing services, namely
Direct reference through registry reference service 3.2.1 direct reference service
Directly referencing a service, as the name implies, is to bypass the registry to get the service provider we want. because we bypass the registry, we are naturally unable to achieve service discovery, and because of a single point of problem, it is impossible to achieve load balancing and high availability, so this mode is not recommended in the production environment.
However, because of its convenience in development, this model can still be tried in the development environment / test environment.
As shown in the figure above, during the joint deployment of the developer students, the machines of the designated service developers need to be directly connected in the project project, while other unspecified services will go to the registry by default. In order to avoid intrusiveness to the project code, we will set up dubbo.properies in the project to deal with different environments, and dubbo.properies will not be added to the version control of the project. It is mainly used to solve the problem of direct connection of services in different environments. the control granularity of services can be accurate to specific services.
3.2.2 referencing services through the registry
Through the registry discovery reference service, Dubbo commonly used reference service way, can achieve automatic service discovery, load balancing. Formal environment calls are basically based on this pattern. There are many kinds of registry implementations, such as Zookeeper/Redis/Multicast. Official recommendation Zookeeper.
3.3 definition of service request structure
The service request structure is a layer of encapsulation after abstracting the registration information of dubbo in the registry. On the one hand, it can improve the development efficiency of developers, and on the other hand, it can reduce the error rate of developers' manual splicing requests.
3.3.1 composition of services
Based on the above analysis based on the protocol, our current agreement will only be locked in dubbo/rest, so we first see what the information registered in the registry of these two protocols looks like.
Dubbo://192.168.1.2:10880/com.service.ProductService?dubbo=2.8&methods=getById,getByNamerest://192.168.1.2:10081/service/com.service.ProductService?dubbo=2.8&methods=getById,getByName
Let's extract the common part of these two agreements.
Definition of dubbo://com.service.ProductService3.3.2 request body
Based on the analysis of the above service structure, the structure of dubbo service request is similar to that of rest service request. We can define different protocol requests as follows.
/ / 1. Dubbo protocol request body definition services.ProductService = (dubbo) = > dubbo.proxyService ({dubboInterface: 'com.service.ProductService', methods: {getById (id) {return [java.Long (id)];}, getByName (name) {return [java.String (name)];},},}) Copy the code / / rest request body definition services.ProductService = (dubbo) = > dubbo.proxyService ({dubboInterface: 'com.service.ProductService', methods: {getById (id) {return {method:' get', query: [parseInt (id)]};}, getByName (name) {return [String (name)] },}); copy code
The biggest difference between the two is the parameter definition. Dubbo needs to be cast to strongly typed, while rest does not.
3.4 maintenance of service definition
After we have finished defining the service, we will face a problem in use. the most direct way is to create a new service file for each service in each project. however, as soon as we use it, we will find that the defined files of a problem request are scattered in different projects, so it is impossible to carry out unified maintenance and upgrade, and the maintenance cost is high.
Our first reaction is that each service is abstracted into a separate NPM package, such as MemberService. We can abstract into @ dubbo-service/member-service, so that we can solve the maintenance problems caused by files scattered in different projects.
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.