久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

基于dubbo protocol的demo怎么實(shí)現(xiàn)

共計(jì) 3063 個(gè)字符,預(yù)計(jì)需要花費(fèi) 8 分鐘才能閱讀完成。

這篇文章主要講解了“基于 dubbo protocol 的 demo 怎么實(shí)現(xiàn)”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著丸趣 TV 小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“基于 dubbo protocol 的 demo 怎么實(shí)現(xiàn)”吧!

說(shuō)明:本文基于 redhat6 做的 demo,jdk 等各種環(huán)境都已經(jīng)就緒了。建議 java 開(kāi)發(fā)者了解 linux 系統(tǒng)。

demo 項(xiàng)目如圖:

運(yùn)行結(jié)果如圖:

2、新建接口服務(wù):com.enson.demo.service.DubboService

代碼:

package com.enson.demo.service;
public interface DubboService {public String printWord(String word);
}

3、實(shí)現(xiàn)接口:com.enson.demo.service.impl.DubboServiceImpl

代碼:

package com.enson.demo.service.impl;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.enson.demo.service.DubboService;
public class DubboServiceImpl implements DubboService{
 @Override
 public String printWord(String word) {String outWord = new SimpleDateFormat( [yyyy-MM-dd HH:mm:ss ] )
 .format(new Date()) + word;
 System.err.println(outWord);
 return outWord;
}

4、創(chuàng)建 provider.xml

?xml version= 1.0

5、創(chuàng)建 test.Provider 類,作為服務(wù)注冊(cè)的入口:

package test;
import java.io.IOException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Provider {public static void main(String[] args) throws IOException {ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {provider.xml});
 context.start();
 
 System.in.read(); //  按任意鍵退出}

以上完成了服務(wù)提供者的編寫(xiě)。

6、創(chuàng)建 com.enson.custom.action.DubboAction

package com.enson.custom.action;
import com.enson.demo.service.DubboService;
public class DubboAction {
 public DubboService dubboService ;
 //Spring  方法注入
 public void setDubboService(DubboService dubboService) {
 this.dubboService = dubboService;
 public String printWord(){
 System.out.println( action printWord 被執(zhí)行!return this.dubboService.printWord(Hello World //  執(zhí)行遠(yuǎn)程方法}

7、創(chuàng)建 cstom.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
  
 
  !--  消費(fèi)方應(yīng)用名,用于計(jì)算依賴關(guān)系,不是匹配條件,不要與提供方一樣  -- 
  dubbo:application name= dubbo-custom-app  / 
 
  !--  使用 zookeeper 注冊(cè)中心暴露發(fā)現(xiàn)服務(wù)地址  -- 
  dubbo:registry address= zookeeper://127.0.0.1:2181  / 
 
  !--  生成遠(yuǎn)程服務(wù)代理,可以和本地 bean 一樣使用 dubboService -- 
  dubbo:reference id= dubboService  interface= com.enson.demo.service.DubboService  / 
 
  !--  普通的 spring bean 的定義  -- 
  bean id= dubboAction   >


8、創(chuàng)建消費(fèi)者類:test.Custom

package test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.enson.custom.action.DubboAction;
public class Custom {public static void main(String[] args) {
 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {  consumer.xml  });
 context.start();
 DubboAction dubboAction = (DubboAction) context.getBean( dubboAction  //  獲取遠(yuǎn)程服務(wù)代理
 String word = dubboAction.printWord();//  執(zhí)行遠(yuǎn)程方法
 System.out.println(word); //  顯示調(diào)用結(jié)果
}

測(cè)試:

1、啟動(dòng) zookeeper。

2、執(zhí)行 Provider。Run as java application

3、執(zhí)行 Custom。Run as java application

查看控制臺(tái)即可。

感謝各位的閱讀,以上就是“基于 dubbo protocol 的 demo 怎么實(shí)現(xiàn)”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì) 基于 dubbo protocol 的 demo 怎么實(shí)現(xiàn)這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是丸趣 TV,丸趣 TV 小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!

正文完
 
丸趣
版權(quán)聲明:本站原創(chuàng)文章,由 丸趣 2023-08-16發(fā)表,共計(jì)3063字。
轉(zhuǎn)載說(shuō)明:除特殊說(shuō)明外本站除技術(shù)相關(guān)以外文章皆由網(wǎng)絡(luò)搜集發(fā)布,轉(zhuǎn)載請(qǐng)注明出處。
評(píng)論(沒(méi)有評(píng)論)
主站蜘蛛池模板: 沾化县| 临朐县| 务川| 博兴县| 溆浦县| 江门市| 澄迈县| 乐陵市| 富源县| 新和县| 剑川县| 西盟| 济宁市| 秦安县| 永定县| 银川市| 天长市| 平顶山市| 涿鹿县| 丽水市| 蒙阴县| 那曲县| 景东| 莎车县| 吉木萨尔县| 云浮市| 綦江县| 盐津县| 永川市| 景洪市| 呈贡县| 湘潭市| 长垣县| 桦川县| 加查县| 沙坪坝区| 临沂市| 融水| 云林县| 西贡区| 沾化县|