成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

Dubbo泛化如何引用

這篇文章主要介紹“Dubbo泛化如何引用”,在日常操作中,相信很多人在Dubbo泛化如何引用問題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”Dubbo泛化如何引用”的疑惑有所幫助!接下來,請(qǐng)跟著小編一起來學(xué)習(xí)吧!

創(chuàng)新互聯(lián)公司專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于做網(wǎng)站、成都網(wǎng)站設(shè)計(jì)、洛浦網(wǎng)絡(luò)推廣、重慶小程序開發(fā)、洛浦網(wǎng)絡(luò)營銷、洛浦企業(yè)策劃、洛浦品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們最大的嘉獎(jiǎng);創(chuàng)新互聯(lián)公司為所有大學(xué)生創(chuàng)業(yè)者提供洛浦建站搭建服務(wù),24小時(shí)服務(wù)熱線:18982081108,官方網(wǎng)址:jinyejixie.com

泛接口調(diào)用方式主要用于客戶端沒有API接口及模型類元的情況,參數(shù)及返回值中的所用POJO均使用Map表示,通常用于框架集成,比如:實(shí)現(xiàn)一個(gè)通用的服務(wù)測(cè)試框架,可通過GenericService調(diào)用所有服務(wù)實(shí)現(xiàn)。 

實(shí)現(xiàn)代碼如下: 

服務(wù)器端代碼:

package com.dubbo.entity;

import java.io.Serializable;

public class Computer implements Serializable{

    private static final long serialVersionUID = 1L;

    private Integer id;

    private String name;

    public Integer getId() {

        return id;

    }

    public void setId(Integer id) {

        this.id = id;

    }

    public String getName() {

        return name;

    }

    public void setName(String name) {

        this.name = name;

    }

}   

package com.dubbo.entity;

import java.io.Serializable;

public class User implements Serializable {

    private static final long serialVersionUID = 1L;

    private Integer id;

    private String name;

    private Computer computer;

    public Integer getId() {

        return id;

    }

    public void setId(Integer id) {

        this.id = id;

    }

    public String getName() {

        return name;

    }

    public void setName(String name) {

        this.name = name;

    }

    public Computer getComputer() {

        return computer;

    }

    public void setComputer(Computer computer) {

        this.computer = computer;

    }

}

package com.dubbo.service;

import com.dubbo.entity.User;

public interface IDubboGenQService {     

    public User queryUser(Integer id);

    public void saveUser(User user);

}

package com.dubbo.service.impl;

import com.dubbo.entity.Computer;

import com.dubbo.entity.User;

import com.dubbo.service.IDubboGenQService;

public class DubboGenQServiceImpl implements IDubboGenQService {

    public User queryUser(Integer id) { 

        User user=new User();

        user.setId(id);

        user.setName("張三"+id);

        Computer computer=new Computer();

        computer.setId(id);

        computer.setName("張三的電腦");

        user.setComputer(computer);

        return user;

    }

    public void saveUser(User user) { 

        System.out.println("用戶保存了");

        System.out.println(user.getName());

        System.out.println(user.getComputer().getName());

    }

dubbo.xml配置:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"

    xsi:schemaLocation="http://www.springframework.org/schema/beans        

    http://www.springframework.org/schema/beans/spring-beans.xsd        

    http://code.alibabatech.com/schema/dubbo        

    http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

    <!-- 指定web服務(wù)名字 -->

    <dubbo:application name="DubboGenQ"/>

    <!-- 聲明服務(wù)注冊(cè)中心 -->

    <dubbo:registry protocol="zookeeper" address="127.0.0.1:2181"/>

    <!-- 指定傳輸層通信協(xié)議 -->

    <dubbo:protocol name="dubbo" port="20880"/>

    <!-- 暴露你的服務(wù)地址 -->

    <dubbo:service 

        ref="dubboGenQService" 

        interface="com.dubbo.service.IDubboGenQService"

        protocol="dubbo"

        cluster="failover"

    />

 </beans>

dubbo 提供者啟動(dòng)

 public class dubboServerStart {

    public static void main(String[] args) throws Exception {

        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("dubbo.xml");

        context.start();

        System.in.read();

    }

}

 客戶端實(shí)現(xiàn):

 import java.io.IOException;

import java.util.HashMap;

import java.util.Map;

import org.springframework.context.ApplicationContext;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.alibaba.dubbo.rpc.service.GenericService;

public class DubboClientStart { 

    public static void main(String[] args) throws IOException {

        ApplicationContext ctx=new ClassPathXmlApplicationContext("dubbo.xml");

        GenericService genericService=(GenericService) ctx.getBean("dubboGenQService");

        Object resultUser = genericService.$invoke("queryUser", 

                new String[] { "java.lang.Integer"}, 

                new Object[] { 1 }); 

        HashMap<String, Object> userMap=(HashMap<String, Object>) resultUser;

        for(Map.Entry<String, Object> entry1: userMap.entrySet()){

            if(entry1.getValue() instanceof HashMap){

                HashMap<String, Object> computerMap=(HashMap<String, Object>) entry1.getValue();

                System.out.println(entry1.getKey());

                for(Map.Entry<String, Object> entry: computerMap.entrySet()){

                    System.out.println("\t"+entry.getValue());

                }

            }else{

                System.out.println(entry1.getKey()+" "+entry1.getValue());

            }

        }

        //演示用戶數(shù)據(jù)的封裝

        Map<String, Object> user = new HashMap<String, Object>(); 

        user.put("name", "張三"); 

        HashMap<String, String> value = new HashMap<String, String>();

        value.put("name", "張三的電腦");

        user.put("computer", value);

        genericService.$invoke("saveUser", new String[]{"com.dubbo.entity.User"}, 

                new Object[]{user});

    }

}

dubbo.xml配置:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"

    xsi:schemaLocation="http://www.springframework.org/schema/beans        

    http://www.springframework.org/schema/beans/spring-beans.xsd        

    http://code.alibabatech.com/schema/dubbo        

    http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

    <!-- 指定web服務(wù)名字 -->

    <dubbo:application name="DubboGenQ"/>

    <!-- 聲明服務(wù)注冊(cè)中心 -->

    <dubbo:registry protocol="zookeeper" address="127.0.0.1:2181"/>

    <!-- 指定傳輸層通信協(xié)議  因?yàn)樵谕慌_(tái)機(jī)器測(cè)試,所以端口不一樣-->

    <dubbo:protocol name="dubbo" port="20881"/>

    <!-- 暴露你的服務(wù)地址 -->

    <dubbo:reference

        id="dubboGenQService" 

        interface="com.dubbo.service.IDubboGenQService"

        protocol="dubbo"

        cache="lru"

        generic="true"

        />

 </beans>

到此,關(guān)于“Dubbo泛化如何引用”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!

文章名稱:Dubbo泛化如何引用
轉(zhuǎn)載注明:http://jinyejixie.com/article2/jpohic.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機(jī)、網(wǎng)站營銷ChatGPT、定制網(wǎng)站外貿(mào)建站、手機(jī)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)
额敏县| 鹿邑县| 忻城县| 江西省| 改则县| 建德市| 册亨县| 青河县| 科尔| 左云县| 沈丘县| 陆川县| 灌阳县| 泰和县| 土默特右旗| 宁陵县| 休宁县| 济宁市| 肇东市| 特克斯县| 班戈县| 濉溪县| 永昌县| 贺兰县| 永丰县| 大英县| 宝清县| 防城港市| 肥东县| 辰溪县| 多伦县| 平顶山市| 永年县| 延津县| 衡山县| 弥渡县| 积石山| 白城市| 高密市| 宜兴市| 大同市|