SoFunction
Updated on 2024-11-14

How python calls the dubbo interface

After the company's back-end service was reconfigured using java, many interfaces used Ali's dubbo protocol. Python can't call the dubbo interface directly, but you can call it through telnet, specifically through the Telnet class of the telnetlib module, which takes only four lines of code to realize:

import telnetlib

# Create telnet class objects
conn = ()
# Connect to the dubbo interface address
(host, port)
#Command Format: interface full name. Method name (parameter 1, parameter 2, parameter 3...) Parameter n) The method is to initiate a dubbo request via telnet, with the same parameters as using telnet alone.
('invoke {}\n'.format(cmd).encode())
# Get telnet return information
conn.read_until('dubbo>'.encode()).decode().split('\r\n')[0]

Split into categories:

class Dubbo(object):
  '''
  Method Invocation Cases:
  conn = Dubbo('127.0.0.1', 18080)
  # Format: interface full name. Method name (parameter 1, parameter 2, parameter 3...) Parameter n)
  cmd = '(268,"sz",1587288615000,1587634215000,0,10)'
  response = ((cmd))
  '''
  dubbo = 'dubbo>'

  def __init__(self,host,port):
     = ()
    (host, port)

  def request(self,cmd):
    ('invoke {}\n'.format(cmd).encode())
    data = .read_until(()).decode().split('\r\n')[0]

    return data

The above is how to call dubbo interface in python details, more information about python call dubbo interface please pay attention to my other related articles!