dubbo Interface Public class service calls

import json, time
import telnetlib
from datetime import datetime


class Dubbo(telnetlib.Telnet):
prompt = 'dubbo>'
coding = 'utf-8'

def __init__(self, host=None, port=0):
super().__init__(host, port)
# 触发dubbo提示符
self.write(b'\n')

def command(self, flag, str_=""):
data = self.read_until(flag.encode())
self.write(str_.encode() + b"\n")
return data

def invoke(self, service_name, method_name, arg):
self.command(Dubbo.prompt, "invoke {0}.{1}({2})".format(service_name, method_name, json.dumps(arg)))
data = self.command(Dubbo.prompt, "")
. Data = data.decode (Dubbo.coding, errors = 'the ignore') Split ( '\ n-') [0] .strip ()

# Telnet connections terminate
self.close ()
return Data

DEF do (Self, Arg):
self.command (Dubbo.prompt, Arg)
Data = self.command (Dubbo.prompt, Arg)
Data = data.decode (Dubbo.coding, errors = 'the ignore'). Split ( '\ n-') [0]. Strip ()

# Telnet connection is terminated
self.close ()
return the data

reference Baidu, someone blog excerpt, forget the sorry

Guess you like

Origin www.cnblogs.com/hufengTE/p/12146523.html