current position:Home>Test Development: self study Dubbo + Python experience summary and sharing

Test Development: self study Dubbo + Python experience summary and sharing

2021-08-23 04:47:06 Test development technology

1. background

With the development of the Internet , The scale of web applications continues to grow , Conventional vertical application architectures can no longer cope , Distributed service architecture and flow computing architecture are imperative , A governance system is needed to ensure the orderly evolution of the architecture .

At present, there are some basic structures in the market :

  • Single application architecture
    • When website traffic is low , Just one app , Deploy all functions together , To reduce deployment nodes and costs .
    • here , Used to simplify the work of adding, deleting, modifying and checking Data access framework (ORM) Is the key .
  • Vertical application architecture
    • When the number of visits increases gradually , Single application increases the acceleration brought by the machine is getting smaller and smaller , Split the application into several unrelated applications , To improve efficiency .
    • here , For accelerating front-end page development Web frame (MVC) Is the key .
  • Distributed service architecture
    • As more and more vertical applications , Interaction between applications is inevitable , Extract core business , As an independent service , Gradually form a stable service center , Enable front-end applications to respond more quickly to changing market demands .
    • here , To improve business reuse and integration Distributed service framework (RPC) Is the key .
  • Flow computing architecture
    • When the service is more and more , Capacity assessment , Problems such as waste of small service resources are gradually emerging , At this time, it is necessary to add a dispatching center to manage the cluster capacity in real time based on the access pressure , Improve cluster utilization .
    • here , For improving machine utilization Resource scheduling and Governance Center (SOA) Is the key .

2. Introduce

Dubbo It is a high-performance and excellent service framework of Alibaba open source , Enables applications to pass high-performance RPC Realize the output and input functions of services , You can talk to spring Seamless integration of framework .

Dubbo It's a high performance , Lightweight open source Java RPC frame , He provides three core competencies : Interface oriented remote method call , Intelligent fault tolerance and load balancing , And automatic service registration and discovery .

3. principle

3.1 The core

Remoting: Network communication framework , Realized sync-over-async and request-response Message mechanism .

RPC: An abstraction of a remote procedure call , Support load balancing , Disaster recovery and clustering .

Registry: The service directory framework is used for service registration and service event publishing and subscription .

3.2 framework

Node role

  • Provider: Service providers that expose services
  • Consumer: The service consumer that invokes the service
  • Registry: Service registry with discovery registry
  • Monitor: The monitoring center that counts the number of service calls and call time
  • Container: Service run container

Call relationship

  • 0、 The service container is responsible for starting , load , Run the service provider
  • 1、 The service provider at startup , Register your services with the registry
  • 2、 Service consumers at startup , Subscribe to the registry for the services you need
  • 3、 The registry returns a list of service provider addresses to the consumer , If there are changes , The registry pushes the change data to the consumer based on the long connection
  • 4、 Serving consumers , From the provider address list , Based on soft load balancing algorithm , Select a provider to invoke , If the call fails , Select another call
  • 5、 Service consumers and providers , Accumulate call times and call time in memory and regularly send statistical data to the monitoring center every minute

characteristic

Connectivity , Robustness, , Scalability , And upgrading to the future architecture . Want to know more , You can go directly to the official website to check :

https://dubbo.apache.org/zh/

4. effect

1、 Transparent remote method calls , Call a remote method just like calling a local method , Simple configuration , There is no API invasion .

2、 Soft load balancing and fault tolerance mechanism , It can be replaced in the intranet F5 Wait for hardware load balancer , cost reduction , Reduce the single point .

3、 Service automatic registration and discovery , It's no longer necessary to write down the service provider address , The registry queries the... Of the service provider based on the interface name IP Address , And can smoothly add or remove service providers .

5. utilize Python Library debugging Dubbo

python Want to achieve dubbo The call of interface can refer to dubbo Mentioned in the official documents of :dubbo Can pass telnet Command service governance , Can pass telnet link dubbo service , Re pass invoke Method call dubbo Interface , For details, see :

https://dubbo.apache.org/zh/docs/v2.7/user/references/telnet/

And in the Python There is a third-party package telnetlib, So we can execute... Through this package telnet command , And then dubbo Interface to call .

Be careful :python Version is 2.7

pip install dubbo_telnet
#-*- coding: utf-8 -*-

import dubbo_telnet
import json
Host = '192.168.0.1'  # Doubble The server IP
Port = 9036  # Doubble Service port 

#  initialization dubbo object 
conn = dubbo_telnet.connect(Host, Port)

#  Set up telnet Connection timeout 
conn.set_connect_timeout(10)

#  Set up dubbo The code of the response returned by the service 
conn.set_encoding('gbk')

#  Show the list of services 
print conn.do("ls")

#  Displays a list of methods for the specified service 
print conn.do("ls XXXService")

#  Method call 
interface = 'XXXService'
method = 'userinfo'
param = user_id
result = conn.invoke(interface, method, param)

print json.dumps(result, sort_keys=True, indent=4, separators=(',', ': '), skipkeys=True, ensure_ascii=False)

#  See :https://hhyo.github.io/2017/10/20/python-dubbo-telnet/

This article is from WeChat official account. - Test development technology (mikezhou_talk) , author : Lipan

The source and reprint of the original text are detailed in the text , If there is any infringement , Please contact the [email protected] Delete .

Original publication time : 2021-08-10

Participation of this paper Tencent cloud media sharing plan , You are welcome to join us , share .

copyright notice
author[Test development technology],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2021/08/20210823044703377Q.html

Random recommended