日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網為廣大站長提供免費收錄網站服務,提交前請做好本站友鏈:【 網站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

Dubbo是阿里巴巴公司開源的一個高性能優秀的服務框架,使得應用可通過高性能的 RPC 實現服務的輸出和輸入功能,可以和Spring框架無縫集成。

Dubbo是一款高性能、輕量級的開源JAVA RPC框架,它提供了三大核心能力:面向接口的遠程方法調用,智能容錯和負載均衡,以及服務自動注冊和發現。

新人一看就懂:Dubbo+Zookeeper的RPC遠程調用框架demo

 

  • provider:暴露服務的服務提供方
  • consumer:調用遠程服務的服務消費方
  • registry:服務注冊于發現的注冊中心
  • monitor:統計服務調用次數和調用時間的監控中心
  • container:服務運行容器

一、dubbo-provider

新人一看就懂:Dubbo+Zookeeper的RPC遠程調用框架demo

 

1、UserInfo

為什么要實現Serializable接口?當我們需要把對象的狀態信息通過網絡進行傳輸,或者需要將對象的狀態信息持久化,以便將來使用時都需要把對象進行序列化。

@Data
public class UserInfo implements Serializable {
 private String account;
 private String password;
}

2、UserService

public interface UserService {
 // 定義用戶登錄的api
 UserInfo login(UserInfo user);
}

3、UserServiceImpl

@Component
@Service(interfaceClass = UserService.class)
public class UserServiceImpl implements UserService {
 public UserInfo login(UserInfo user) {
 UserInfo reUser = new UserInfo();
 reUser.setAccount("登錄的賬號為:"+user.getAccount());
 reUser.setPassword("登錄的密碼為:"+user.getPassword());
 return reUser;
 }
}

4、DubboProviderApplication

@SpringBootApplication
@EnableDubboConfiguration // 啟用dubbo自動配置
public class DubboProviderApplication {
 public static void main(String[] args) {
 SpringApplication.run(DubboProviderApplication.class, args);
 }
}

5、pom.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">
 <modelVersion>4.0.0</modelVersion>
 <groupId>com.boot.dubbo.demo</groupId>
 <artifactId>dubbo-provider</artifactId>
 <version>0.0.1-SNAPSHOT</version>
 <packaging>jar</packaging>
 <name>dubbo-provider</name>
 <description>Demo project for Spring Boot</description>
 <parent>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-parent</artifactId>
 <version>2.0.6.RELEASE</version>
 <relativePath/> <!-- lookup parent from repository -->
 </parent>
 <properties>
 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
 <java.version>1.8</java.version>
 </properties>
 <dependencies>
 <dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-web</artifactId>
 </dependency>
 <!--Dubbo依賴-->
 <dependency>
 <groupId>com.alibaba.spring.boot</groupId>
 <artifactId>dubbo-spring-boot-starter</artifactId>
 <version>2.0.0</version>
 </dependency>
 <!--自動生成getter,setter,equals,hashCode和toString等等-->
 <dependency>
 <groupId>org.projectlombok</groupId>
 <artifactId>lombok</artifactId>
 <version>1.16.20</version>
 <scope>provided</scope>
 </dependency>
 <!--Zookeeper客戶端-->
 <dependency>
 <groupId>com.101tec</groupId>
 <artifactId>zkclient</artifactId>
 <version>0.10</version>
 </dependency>
 <!--Zookeeper依賴,排除log4j避免依賴沖突-->
 <dependency>
 <groupId>org.apache.zookeeper</groupId>
 <artifactId>zookeeper</artifactId>
 <version>3.4.10</version>
 <exclusions>
 <exclusion>
 <groupId>org.slf4j</groupId>
 <artifactId>slf4j-log4j12</artifactId>
 </exclusion>
 <exclusion>
 <groupId>log4j</groupId>
 <artifactId>log4j</artifactId>
 </exclusion>
 </exclusions>
 </dependency>
 <dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-test</artifactId>
 <scope>test</scope>
 </dependency>
 </dependencies>
 <build>
 <plugins>
 <plugin>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-maven-plugin</artifactId>
 </plugin>
 </plugins>
 </build>
</project>

6、application.yml

spring:
 dubbo:
 application:
 name: dubbo-provider
 protocol:
 name: dubbo
 port: 20880
 registry:
 address: zookeeper://127.0.0.1:2181

二、dubbo-consumer

新人一看就懂:Dubbo+Zookeeper的RPC遠程調用框架demo

 

1、UserController

@RestController
public class UserController {
 @Reference // 引用dubbo服務器提供服務器接口
 private UserService userService;
 @GetMapping("/login")
 public UserInfo login(UserInfo userInfo) {
 return userService.login(userInfo);
 }
}

2、DubboConsumerApplication

@SpringBootApplication
@EnableDubboConfiguration // 啟用dubbo自動配置
public class DubboConsumerApplication {
 public static void main(String[] args) {
 SpringApplication.run(DubboConsumerApplication.class, args);
 }
}

3、pom.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">
 <modelVersion>4.0.0</modelVersion>
 <groupId>com.boot.dubbo.demo</groupId>
 <artifactId>dubbo-consumer</artifactId>
 <version>0.0.1-SNAPSHOT</version>
 <packaging>jar</packaging>
 <name>dubbo-consumer</name>
 <description>Demo project for Spring Boot</description>
 <parent>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-parent</artifactId>
 <version>2.0.6.RELEASE</version>
 <relativePath/> <!-- lookup parent from repository -->
 </parent>
 <properties>
 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
 <java.version>1.8</java.version>
 </properties>
 <dependencies>
 <dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-web</artifactId>
 </dependency>
 <!--依賴dubbo-provider服務提供者-->
 <dependency>
 <groupId>com.boot.dubbo.demo</groupId>
 <artifactId>dubbo-provider</artifactId>
 <version>0.0.1-SNAPSHOT</version>
 </dependency>
 <!--Dubbo依賴-->
 <dependency>
 <groupId>com.alibaba.spring.boot</groupId>
 <artifactId>dubbo-spring-boot-starter</artifactId>
 <version>2.0.0</version>
 </dependency>
 <!--Zookeeper客戶端-->
 <dependency>
 <groupId>com.101tec</groupId>
 <artifactId>zkclient</artifactId>
 <version>0.10</version>
 </dependency>
 <!--Zookeeper依賴,排除log4j避免依賴沖突-->
 <dependency>
 <groupId>org.apache.zookeeper</groupId>
 <artifactId>zookeeper</artifactId>
 <version>3.4.10</version>
 <exclusions>
 <exclusion>
 <groupId>org.slf4j</groupId>
 <artifactId>slf4j-log4j12</artifactId>
 </exclusion>
 <exclusion>
 <groupId>log4j</groupId>
 <artifactId>log4j</artifactId>
 </exclusion>
 </exclusions>
 </dependency>
 <dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-test</artifactId>
 <scope>test</scope>
 </dependency>
 </dependencies>
 <build>
 <plugins>
 <plugin>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-maven-plugin</artifactId>
 </plugin>
 </plugins>
 </build>
</project>

4、application.yml

spring:
 dubbo:
 application:
 name: dubbo-consumer
 protocol:
 name: dubbo
 port: 20880
 registry:
 address: zookeeper://127.0.0.1:2181
server:
 port: 8081

三、Zookeeper安裝配置

「鏈接」

「鏈接」

「鏈接」

四、項目啟動

新人一看就懂:Dubbo+Zookeeper的RPC遠程調用框架demo

 

五、查看Zookeeper服務注冊情況

新人一看就懂:Dubbo+Zookeeper的RPC遠程調用框架demo

 

六、通過瀏覽器發送請求(dubbo-provider的服務注冊到Zookeeper上,dubbo-consumer消費者可以調用注冊的服務)。

到此,rpc遠程調用服務通了!感興趣的話可以去學習下。


原文鏈接:https://blog.csdn.net/sinat_27933301/article/details/100991670

分享到:
標簽:Dubbo
用戶無頭像

網友整理

注冊時間:

網站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網站吧!
最新入駐小程序

數獨大挑戰2018-06-03

數獨一種數學游戲,玩家需要根據9

答題星2018-06-03

您可以通過答題星輕松地創建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學四六

運動步數有氧達人2018-06-03

記錄運動步數,積累氧氣值。還可偷

每日養生app2018-06-03

每日養生,天天健康

體育訓練成績評定2018-06-03

通用課目體育訓練成績評定