##简介
dubbo服务发布之后,我们可以利用telnet命令进行调试、管理。更多资料参见Telnet命令参考手册
telnet 调用示例:
$ telnet 172.17.103.110 9097
Trying 172.17.103.110...
Connected to 172.17.103.110.
Escape character is '^]'.
dubbo>ls com.oppo.sso.service.onekey.IOnekeyRegister
register
dubbo>invoke com.oppo.sso.service.onekey.IOnekeyRegister.register({"applicationKey":"mac","imei":"","mobile":"13244448888","createIP":"127.0.0.1","createBy":"172.17.0.1"})
{"configCountry":null,"userIdLong":0,"appPackage":null,"appVersion":null,"accountName":null,"romVersion":null,"resultCode":3001,"thirdStatus":null,"registerType":0,"sendChannel":null,"operator":null,"manufacturer":null,"password":null,"osVersion":null,"lock":false,"model":null,"visitorLocked":false,"OK":false,"brand":null,"email":null,"createIP":null,"deny":false,"encryptEmail":null,"sessionKey":null,"thirdId":null,"passwordOriginal":null,"mobile":null,"applicationKey":null,"thirdpartyOk":false,"userAgent":null,"userName":null,"resultDesc":"应用不存在","userId":0,"encryptMobile":null,"emailStatus":null,"createBy":null,"freePwd":false,"changeTimes":0,"createTime":null,"mobileStatus":null,"oldLock":false,"codeTimeout":null,"lastUpdate":null,"imei":null,"sessionTimeout":0,"sdkVersion":null,"networkID":0,"status":null}
elapsed: 98 ms.
dubbo>
这个参数 我要说一下 如果直接调用服务端java 很多教程都是传递的json参数
而dubbo端接收的可能不是json,所以如果不是 请直接传一个list参数即可 換一種方法说就是不要写参数名 直接写参数 也就是
command = ‘invoke’ + dubbo 服务名 + 方法名 (‘1165’)
Python实现
import json
import telnetlib
class Dubbo(telnetlib.Telnet):
prompt = 'dubbo>'
coding = 'utf-8'
def __init__(self, host=None, port=0,):
super().__init__(host, port)
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):
command_str = "invoke {0}.{1}{2}".format(
service_name, method_name,arg
self.command(Dubbo.prompt, command_str)
data = self.command(Dubbo.prompt, "")
data = json.loads(data.decode(Dubbo.coding,
errors='ignore').split('\n')[0].strip())
return data
def do(self, arg):
command_str = arg
print(command_str)
self.command(Dubbo.prompt, command_str)
data = self.command(Dubbo.prompt, command_str)
print(data)
data = data.decode(Dubbo.coding, errors='ignore').split('\n')[1].strip()
print(data)
return data
if __name__ == '__main__':
conn = Dubbo('172.17.103.110', 9097)
command_str1 = 'invoke com.welab.loan.finance.service.CreditUserAccountService.findByUserAndProductCode(624101,"abcded")'
print(conn.do("ls"))#打印所有服务,方便调试
print(conn.do(command_str1))
data=(624101,"abcded")
result = conn.invoke(
"com.oppo.sso.service.onekey.IOnekeyRegister",
"register",
data
)
print(result)```