• dubbo telnet使用


    紧急情况下可能需要直接手动调用接口,而生产环境只有服务提供者,消费者暂时不方便操作时,可通过telnet进行触发。

    举个例子:

    
    
    	com.alibaba
    	fastjson
    	1.2.51
    
    
    package com.alibaba.dubbo.samples.cache.entity;
    
    import java.io.Serializable;
    import java.util.List;
    
    
    public class PersonInfo implements Serializable {
    
    
        private static final long serialVersionUID = -7159408033070746291L;
    
        private String sname;
        private Integer sage;
        private List parents;
        private List areas;
    
        public String getSname() {
            return sname;
        }
    
        public void setSname(String sname) {
            this.sname = sname;
        }
    
        public Integer getSage() {
            return sage;
        }
    
        public void setSage(Integer sage) {
            this.sage = sage;
        }
    
        public List getParents() {
            return parents;
        }
    
        public void setParents(List parents) {
            this.parents = parents;
        }
    
        public List getAreas() {
            return areas;
        }
    
        public void setAreas(List areas) {
            this.areas = areas;
        }
    }
    
    
    package com.alibaba.dubbo.samples.cache.api;
    
    
    import com.alibaba.dubbo.samples.cache.entity.PersonInfo;
    
    public interface StudentService {
    
        boolean save(PersonInfo personInfo,String operator);
    
        PersonInfo findByName(String name);
    }
    
    
    package com.alibaba.dubbo.samples.cache.impl;
    
    import com.alibaba.dubbo.samples.cache.api.StudentService;
    import com.alibaba.dubbo.samples.cache.entity.PersonInfo;
    import com.alibaba.fastjson.JSON;
    import com.google.common.collect.Lists;
    
    import java.util.List;
    
    
    public class StudentServiceImpl implements StudentService {
        @Override
        public boolean save(PersonInfo personInfo, String operator) {
            System.out.println(">>>>>>operator:" + operator);
            System.out.println(">>>>>>personInfo:" + JSON.toJSONString(personInfo));
            return true;
        }
    
        @Override
        public PersonInfo findByName(String name) {
            PersonInfo c = new PersonInfo();
            c.setSname(name);
            c.setSage(12);
            List parent = Lists.newArrayList();
            PersonInfo father = new PersonInfo();
            father.setSage(40);
            father.setSname(name + "#father");
            parent.add(father);
            c.setParents(parent);
    
            List areas = Lists.newArrayList("杭州", "上海");
            c.setAreas(areas);
            return c;
        }
    
    //    public static void main(String[] args) { //用以生成json串,需要自行在string串中补充"class"一项
    //        PersonInfo c = new PersonInfo();
    //        c.setSname("testName123");
    //        c.setSage(12);
    //        List parent = Lists.newArrayList();
    //        PersonInfo father = new PersonInfo();
    //        father.setSage(40);
    //        father.setSname("testName123#father");
    //        PersonInfo mother = new PersonInfo();
    //        mother.setSage(33);
    //        mother.setSname("testName123#mother");
    //        parent.add(father);
    //        parent.add(mother);
    //        c.setParents(parent);
    //
    //        List areas = Lists.newArrayList("杭州", "上海");
    //        c.setAreas(areas);
    //        System.out.println(JSON.toJSONString(c));
    //    }
    }
    
    
    
    
    
    
        
    
        
    
         
    
        
        
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144

    然后启动服务。

    windows下执行cmd命令: telnet 127.0.0.1 20880

    然后是invoke的使用。

    像案例中的StudentService #findByName这种简单的。可直接执行invoke StudentService.findByName(“testSname”)

    如果是复杂对象,比如StudentService#save这种。则需要将入参转换成json串,然后在json串中补上“class”一项,用于InvokeTelnetHandler类进行转换。

    本例中json串结果如下(注释处打开执行后补全“class”即可):

    {“class”:“com.alibaba.dubbo.samples.cache.entity.PersonInfo”,“areas”:[“杭州”,“上海”],“parents”:[{“class”:“com.alibaba.dubbo.samples.cache.entity.PersonInfo”,“sage”:40,“sname”:“testName123#father”},{“class”:“com.alibaba.dubbo.samples.cache.entity.PersonInfo”,“sage”:33,“sname”:“testName123#mother”}],“sage”:12,“sname”:“testName123”}

    然后执行命令组装后如下:

    invoke StudentService.save({“class”:“com.alibaba.dubbo.samples.cache.entity.PersonInfo”,“areas”:[“杭州”,“上海”],“parents”:[{“class”:“com.alibaba.dubbo.samples.cache.entity.PersonInfo”,“sage”:40,“sname”:“testName123#father”},{“class”:“com.alibaba.dubbo.samples.cache.entity.PersonInfo”,“sage”:33,“sname”:“testName123#mother”}],“sage”:12,“sname”:“testName123”},“admin”)

    执行效果如图:

    官网telnet相关地址:

    1、http://dubbo.apache.org/zh-cn/docs/user/references/telnet.html

    2、http://dubbo.apache.org/zh-cn/docs/user/references/qos.html

  • 相关阅读:
    《代码随想录》刷题笔记——字符串篇【java实现】
    Java版本+企业电子招投标系统源代码+支持二开+招投标系统+中小型企业采购供应商招投标平台
    智能运维应用之道,告别企业数字化转型危机
    c++ call_once 使用详解
    规划兼职工作
    MySQL 有哪些常见的面试题
    什么是Bean的循环依赖?解决方案是什么?
    Laravel 运行队列处理器 queue:work 与 queue:listen 区别及 Windows 终端命令问题
    人脸106和240点位检测解决方案
    Flask框架——Sijax
  • 原文地址:https://blog.csdn.net/m0_67266585/article/details/126327744