zookeeper
下载地址 :https://archive.apache.org/dist/zookeeper/
- 修改conf下zoo_sample.cfg - >zoo.cfg
 - bin下启动zkServer.cmd
 - 启动成功 :binding to port 0.0.0.0/0.0.0.0:2181
 
问题1:zookeper安装
1.去官网下载apache-zookeeper-3.6.2-bin.tar.gz名字中带有bin的压缩包(就不会出现闪退)
 2.将conf目录下zoo_sample.cfg文件重命名为zoo.cfg
 3.双击zk.Server.cmd启动程序
问题2:注册中心推荐zookeeper
下载链接:在3.5.5版本后,官方提供了bin的包,可以不需要配置环境,直接上手查看
之后以管理员方式启动bin文件夹中的cmd文件
会报错,我们需要吧conf里的,zoo_simple复制一份,改成zoo.cof
问题3:修改zookeeper端口号
zoo.cfg添加
    admin.serverPort=8887
 
问题4:出现ZooKeeper audit is disabled.为日志记录,有无所谓
修改zkServer.cmd添加
"-Dzookeeper.audit.enable=true",以管理员身份运行,启动zkCli.cmd查看 ls /
Dubbo
下载地址 :https://github.com/apache/dubbo-admin/tree/master,Download-ZIP
1.dubbo为什么性能高
rpc框架的速度却决于序列化方式和网络传输方式
本地对象在网络上传输必须要实现serializable接口,序列化方案有xml,json,二进制流。。
dubbo采用二进制流(最快),并且dubbo采用socket通信能建立长连接,不用像http需要七步(三握手四挥手)
dubbo可视化管理,dubboAdmin和minitor。
dubbo-admin
链接:https://github.com/apache/dubbo-admin
下载好之后,这个是dubbo的一个服务管理中心,可以看到我们注册的服务
 
用cmd打开,mvn clean package -Dmaven.test.skip=true,打成jar包
过程可能有点慢,耐心等待
完成之后,把打包好的jar放入zookeeper根目录
 
之后先启动zookeeper,再跑jar包

查看是否连接成功
 
 注意端口号,8080,如果提示冲突,就是跟zookeeper服务端冲突,用上面zoo.cfg修改端口号即可
zookeeper:注册中心
dubbo-admin:是一个监控管理后台
举例
provider,服务端server
 
package com.tang.service;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.stereotype.Component;
@Service//在项目一启动就注册到注册中心,导入dubbo包内的
@Component//为什么不加service注解,应为dubbo的注册service,用于区分
public class TicketServiceImpl implements TicketService{
    @Override
    public String getTicket() {
        return "好好学习,天天向上";
    }
}
 
package com.tang.service;
public interface TicketService {
    public String getTicket();
}
 
application.properties
server.port=8001
#注册中心地址
dubbo.registry.address=zookeeper://127.0.0.1:2181
#服务名字
dubbo.application.name=privoder1
#那些服务要注册
dubbo.scan.base-packages=com.tang.service
# dubbo端口号修改,跟admin监控页面冲突
dubbo.protocol.port=20881
 
启动,启动后查看dubbo-admin
 
启动过程可能遇到端口冲突问题
windows查询端口占用命令 :netstat -ano | findstr 8080
干掉端口进程 :taskkill /f /pid 28808
linux相关命令 :netstat -anp | grep 8080
ps -ef | grep java
kill -9
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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.tang</groupId>
    <artifactId>provider-server</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>provider-server</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>8</java.version>
    </properties>
    <dependencies>
        <!--dubbo-->
        <dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo-spring-boot-starter</artifactId>
            <version>2.7.3</version>
        </dependency>
        <dependency>
            <!--zkclient,zookeeper客户端-->
            <groupId>com.github.sgroschupf</groupId>
            <artifactId>zkclient</artifactId>
            <version>0.1</version>
        </dependency>
        <!-- 引入zookeeper 并且解决日志冲突-->
        <dependency>
            <groupId>org.apache.curator</groupId>
            <artifactId>curator-framework</artifactId>
            <version>2.12.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.curator</groupId>
            <artifactId>curator-recipes</artifactId>
            <version>2.12.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.zookeeper</groupId>
            <artifactId>zookeeper</artifactId>
            <version>3.4.14</version>
            <!--排除这个slf4j-log4j12-->
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-log4j12</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </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>
 
customer,客户端server:
package com.tang.service;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Service;
@Service//这里要用spring的注解哟,只有spring可以字自动装配
public class UserService {
    //想拿到票,需要调用远程服务,拿到我们服务之者的方法,要去注册中心拿服务
    @Reference//引用 Pom坐标可以定义路径相同的接口名
    TicketService ticketService;
    public  void buyTicket(){
        String getTicket = ticketService.getTicket();
        System.out.println("注册中心zk拿到==> "+getTicket);
    }
}
 
package com.tang.service;
public interface TicketService {
    public String getTicket();
}
 
package com.tang;
import com.tang.service.UserService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class ConsumerServerApplicationTests {
    @Autowired
    UserService userService;
    @Test
    void contextLoads() {
        userService.buyTicket();
    }
}
 

步骤:
前提:zookeeper服务已开启!
- 提供者服务 
  
- 导入依赖
 - 配置文件,注册中心地址,服务发现名和要扫描的服务
 - 想要被注册的服务上加上dubbo的service注解和spring的compent注解
 
 - 消费者如何消费 
  
- 导入依赖
 - 配置文件,服务发现名,注册中心地址
 - 我们需要在客户端建立一个一样的服务者接口,直接远程注入就可以使用这个服务的方法了,远程调用注解dubbo的@Reference
 
 



















