原創(chuàng)文章,歡迎轉(zhuǎn)載。轉(zhuǎn)載請(qǐng)注明:轉(zhuǎn)載自IT人故事會(huì),謝謝!
原文鏈接地址:『高級(jí)篇』docker之課程管理dubbo入門(mén)操練(14)專注于為中小企業(yè)提供成都網(wǎng)站制作、成都網(wǎng)站建設(shè)服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)廣安免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了千余家企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過(guò)網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
接下來(lái)我們即將開(kāi)始說(shuō)課程管理,課程服務(wù)他是基于dubbo實(shí)現(xiàn)的,所以先來(lái)預(yù)熱下,dubbo,對(duì)不熟悉的dubbo的老鐵進(jìn)行一下講解。 源碼:https://github.com/limingios/dubbo.git
高性能的基于java的,RPC框架。dubbo是阿里巴巴開(kāi)源的一個(gè)項(xiàng)目,就像大多的RPC框架,dubbo的思想圍繞一個(gè)服務(wù),指定一個(gè)方法的參數(shù)和返回值,這個(gè)方法可以被遠(yuǎn)程調(diào)用的,在服務(wù)端,會(huì)實(shí)現(xiàn)這個(gè)接口,會(huì)運(yùn)行dubbo的服務(wù)用來(lái)處理客戶端的調(diào)用,在客戶端,會(huì)有一個(gè)存根它提供和服務(wù)端想通的方法。其實(shí)這些概念用java的術(shù)語(yǔ):首先要定義一個(gè)接口,這個(gè)接口在服務(wù)端和客戶端公用,服務(wù)端會(huì)完成這個(gè)接口的實(shí)現(xiàn),客戶端通過(guò)接口的描述來(lái)調(diào)用服務(wù)端。
用了本地調(diào)用。
provider.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://dubbo.apache.org/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
<!-- 提供方應(yīng)用信息,用于計(jì)算依賴關(guān)系 -->
<dubbo:application name="demo-provider" />
<!-- 使用multicast廣播注冊(cè)中心暴露服務(wù)地址 -->
<dubbo:registry register="false" />
<!-- 用dubbo協(xié)議在20880端口暴露服務(wù) -->
<dubbo:protocol name="dubbo" port="20880" />
<!-- 聲明需要暴露的服務(wù)接口 -->
<dubbo:service interface="com.alibaba.dubbo.demo.DemoService" ref="demoService" />
<!-- 和本地bean一樣實(shí)現(xiàn)服務(wù) -->
<bean id="demoService" class="com.alibaba.dubbo.demo.provider.DemoServiceImpl" />
</beans>
consumer.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>dubbo-demo</artifactId>
<groupId>com.idig8</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>dubbo-demo-consumer</artifactId>
<dependencies>
<dependency>
<groupId>com.idig8</groupId>
<artifactId>dubbo-demo-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.6.4</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.0.RELEASE</version>
</dependency>
</dependencies>
</project>
package com.idig8.springboot.dubbo.demo;
public interface DemoService {
String sayHello(String name);
}
對(duì)外提供的maven坐標(biāo)如下:
<dependency>
<groupId>com.idig8</groupId>
<artifactId>dubbo-demo-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- springboot parent -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
</parent>
<!-- springboot dubbo starter -->
<dependency>
<groupId>io.dubbo.springboot</groupId>
<artifactId>spring-boot-starter-dubbo</artifactId>
<version>1.0.0</version>
</dependency>
<!-- api dependence -->
<dependency>
<groupId>com.idig8</groupId>
<artifactId>dubbo-demo-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
package com.idig8.springboot.dubbo.demo.provider;
import com.alibaba.dubbo.config.annotation.Service;
import com.idig8.springboot.dubbo.demo.DemoService;
@Service
public class DemoServiceImpl implements DemoService {
public String sayHello(String name) {
return "Hello, " + name + " (from Spring Boot)";
}
}
spring.dubbo.application.name=demo-provider
#這里使用廣播的注冊(cè)方式,
#如果有Can't assign address異常需要加vm參數(shù):
#-Djava.net.preferIPv4Stack=true
spring.dubbo.registry.address=multicast://224.5.6.7:1234
spring.dubbo.protocol.name=dubbo
spring.dubbo.protocol.port=20880
spring.dubbo.scan=com.idig8.springboot.dubbo.demo.provider
package com.idig8.springboot.dubbo.demo.provider;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MainProvider {
public static void main(String[] args) {
SpringApplication.run(MainProvider.class,args);
}
}
<!-- springboot parent -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
</parent>
<!-- springboot web starter -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- springboot dubbo starter -->
<dependency>
<groupId>io.dubbo.springboot</groupId>
<artifactId>spring-boot-starter-dubbo</artifactId>
<version>1.0.0</version>
</dependency>
<!-- api dependency -->
<dependency>
<groupId>com.idig8</groupId>
<artifactId>dubbo-demo-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
package com.idig8.springboot.dubbo.demo.consumer;
import com.alibaba.dubbo.config.annotation.Reference;
import com.idig8.springboot.dubbo.demo.DemoService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class DemoConsumerController {
@Reference
private DemoService demoService;
@RequestMapping("/sayHello")
public String sayHello(@RequestParam String name) {
return demoService.sayHello(name);
}
}
server.port=8080
#dubbo config
spring.dubbo.application.name=demo-consumer
#這里使用廣播的注冊(cè)方式,
#如果有Can't assign address異常需要加vm參數(shù):
#-Djava.net.preferIPv4Stack=true
spring.dubbo.registry.address=multicast://224.5.6.7:1234
spring.dubbo.scan=com.idig8.springboot.dubbo.demo.consumer
package com.idig8.springboot.dubbo.demo.consumer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Main {
public static void main(String[] args) {
SpringApplication.run(Main.class,args);
}
}
PS:dubbo的入門(mén)也就到這里,從spring 和springboot 對(duì)dubbo的整合。
流程基本之前也說(shuō),api 建立接口,provider 實(shí)現(xiàn)接口, consumer 調(diào)用接口。
網(wǎng)站欄目:『高級(jí)篇』docker之課程管理dubbo入門(mén)操練(14)
網(wǎng)站地址:http://m.rwnh.cn/article30/jepppo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航、網(wǎng)站設(shè)計(jì)、App開(kāi)發(fā)、服務(wù)器托管、電子商務(wù)、網(wǎng)站收錄
聲明:本網(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í)需注明來(lái)源: 創(chuàng)新互聯(lián)