当前位置: 代码迷 >> 综合 >> 01-dubbo-provide
  详细解决方案

01-dubbo-provide

热度:38   发布时间:2023-10-24 06:38:16.0

什么是灰度发布

1、100台机器,先来发布10台。看效果,不错,则发布到所有的。

2、发布版本不稳定,100台,先来10台看看效果,发现不错,则全部发布

dubbo的三大核心功能

01-dubbo-provide

什么是RPC

01-dubbo-provide

 

Zookeeper目录服务

01-dubbo-provide

注册流程说明;

01-dubbo-provide

 

zookeeper配置

#下载

[root@centos701 software]# wget https://mirrors.bfsu.edu.cn/apache/zookeeper/zookeeper-3.6.3/apache-zookeeper-3.6.3-bin.tar.gz

#解压

[root@centos701 software]# tar -zxvf apache-zookeeper-3.6.3-bin.tar.gz 

#创建数据目录

[root@centos701 conf]# mkdir -p /root/software/apache-zookeeper-3.6.3-bin/conf/data

#修改

[root@centos701 software]# cd apache-zookeeper-3.6.3-bin/conf

[root@centos701 conf]# vi zoo.cfg 

       dataDir=/root/software/apache-zookeeper-3.6.3-bin/conf/data

#启动zk

[root@centos701 bin]# cd /root/software/apache-zookeeper-3.6.3-bin/bin

[root@centos701 bin]# ./zkServer.sh start

[root@centos701 bin]# ps -ef | grep zookeeper    

#监听端口
       [root@centos701 bin]# lsof -i:2181

#关闭zk服务

[root@centos701 bin]# ./zkServer.sh  stop

#启动zk客户端

[root@centos701 bin]# ./zkCli.sh 

#连接其他客户端

[root@centos701 bin]#    sh zkCli.sh -server ip:port     

[root@centos701 bin]# ./zkCli.sh -server localhost:2182  

 

 

搭建Dubbo

0、知识点

0.1、使用 @DubboService :在spring启动的时候,创建bean对象,并拼接一个url。保存到指定的注册中心      

0.2、dubbo.application.name  配置服务的名字,如果多个名字相同,则注册成一个集群

0.3   dubbo.application.name  应用名称

0.4   dubbo.registry.address zk 注册地址

0.5  dubbo.protocol.name=dubbo   #协议名称 dubbo

0.6  dubbo.protocol.port=20881  #服务自身的端口  默认20880

0.7  <dubbo:annotation package="com.package.to.be.scanned" />   #指定扫描包,找到@Service  @DubboService  (2个都是dubbo的注解) 

0.8  dubbo.consumer.check=false   #检查提供者时候启动,提供者没有启动的话就报错。设置为false为不检查。提供者启动不启动都不会报错了

0.9  @Autowired  是从当前应用的IOC容器中注入对象

1.0  @DubboReference  #从zk中获取调用

 

01-dubbo-provide

 

 

2、创建父工程

3、父工程的pom

4、引入依赖

5、创建接口和实现类 配置 启动


1、创建父工程

2、父工程的pom 引入依赖

  <dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>org.apache.dubbo</groupId><artifactId>dubbo-spring-boot-starter</artifactId><version>2.7.8</version></dependency><dependency><groupId>org.apache.curator</groupId><artifactId>curator-framework</artifactId><version>4.0.1</version></dependency><!-- 链接zk的  --><dependency><groupId>org.apache.curator</groupId><artifactId>curator-recipes</artifactId><version>4.0.1</version></dependency>

3、创建接口和实现类

public interface SayInterface {void sayHello(String name);
}@DubboService
public class SayInterfaceImpl implements SayInterface {@Overridepublic void sayHello(String name) {System.out.println("访问到了 sayHello 方法");}
}

4、配置

#注册中心的地址  http://192.168.181.138:2181/
dubbo.registry.address=zookeeper://192.168.181.138:2181
#注册中心的端口
dubbo.registry.port=20080
#定义名称
dubbo.application.name=dubbo-provide

5、启动之后可以再zk中看到链接信息

01-dubbo-provide

 

 

/dubbo/com.nuc.service.SayInterface/providers/dubbo%3A%2F%2F192.168.181.1%3A20880%2Fcom.nuc.service.SayInterface%3Fanyhost%3Dtrue%26application%3Ddubbo-provide%26default%3Dtrue%26deprecated%3Dfalse%26dubbo%3D2.0.2%26dynamic%3Dtrue%26generic%3Dfalse%26interface%3Dcom.nuc.service.SayInterface%26metadata-type%3Dremote%26methods%3DsayHello%26pid%3D34420%26release%3D2.7.8%26side%3Dprovider%26timestamp%3D1621099069273

 

"/dubbo/com.nuc.service.SayInterface/providers/dubbo://192.168.181.1:20880/com.nuc.service.SayInterface?anyhost=true&application=dubbo-provide&default=true&deprecated=false&dubbo=2.0.2&dynamic=true&generic=false&interface=com.nuc.service.SayInterface&metadata-type=remote&methods=sayHello&pid=34420&release=2.7.8&side=provider&timestamp=1621099069273"