springboot+dubbo+zookeeper

        Dubbo工作原理:

1.下载zookeeper 

        https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.7.0/apache-zookeeper-3.7.0-bin.tar.gz

2.安装zookeeper

        1)windows下的安装

                解压下载的压缩包

        

               然后在conf文件夹下复制粘贴zoo_sample.cfg,把复制的文件名称修改为zoo.cfg

               进入bin文件夹,双击zkServer.cmd

        2)linux下的安装

                https://www.cnblogs.com/expiator/p/9853378.html

3.创建provider  springboot项目

         1)provider 服务提供者

               引入依赖
                

                <dependency>
                    <groupId>org.apache.dubbo</groupId>
                    <artifactId>dubbo-spring-boot-starter</artifactId>
                    <version>3.0.0</version>
                </dependency>

                <dependency>
                      <groupId>org.apache.dubbo</groupId>
                      <artifactId>dubbo-dependencies-zookeeper</artifactId>
                      <version>3.0.0</version>
                      <type>pom</type>
                        <exclusions>
                            <exclusion>
                                <groupId>org.slf4j</groupId>
                                <artifactId>slf4j-log4j12</artifactId>
                            </exclusion>
                        </exclusions>
                </dependency>  

                exclusion 排除slf4j包

                写入配置文件

                        

dubbo.application.name=provider    // 应用名
dubbo.scan.base-packages=com.xukf.service    // 扫描提供的接口
dubbo.registry.address=zookeeper://127.0.0.1:2181    // zookeeper注册中心地址

                伪代码:

public interface TikctService {

	public String hollew();
	
}
package com.xukf.service.impl;

import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Component;

import com.xukf.service.TikctService;

@DubboService
@Component
public class TiketServiceImpl implements TikctService {

	@Override
	public String hollew() {
		return "HOLLE,WORD!";
	}

}

 4.查看dubbo-admin

        1)下载:https://github.com/apache/incubator-dubbo/tree/2.5.x

        2) 解压

         3)打包:mvn clean package -Dmaven.test.skip=true // 跳过单元测试打包

        4)把打出的war包放到tomcat中运行

        5)查看结果

 5.创建concumer  springboot项目

        1)provider 服务提供者

               引入依赖
                

                <dependency>
                    <groupId>org.apache.dubbo</groupId>
                    <artifactId>dubbo-spring-boot-starter</artifactId>
                    <version>3.0.0</version>
                </dependency>

                <dependency>
                      <groupId>org.apache.dubbo</groupId>
                      <artifactId>dubbo-dependencies-zookeeper</artifactId>
                      <version>3.0.0</version>
                      <type>pom</type>
                        <exclusions>
                            <exclusion>
                                <groupId>org.slf4j</groupId>
                                <artifactId>slf4j-log4j12</artifactId>
                            </exclusion>
                        </exclusions>
                </dependency>  

                exclusion 排除slf4j包

                写入配置文件

dubbo.application.name=consumer    //应用名
dubbo.registry.address=zookeeper://127.0.0.1:2181 // 注册中心

                伪代码:

package com.xukf.service;

import org.springframework.stereotype.Service;

@Service
public interface TikctService {

	public String hollew();
	
}
package com.xukf.controller;

import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xukf.service.TikctService;

@Controller
public class IndexController {

	@DubboReference
	TikctService tikctService;
	
	@RequestMapping("/index")
	@ResponseBody
	public String index() {
		return tikctService.hollew();
	}
	
}

 6.查看运行结果

备注:

         provider项目中的端口8001

         consumer项目中的端口8002

        dubbo-admin中的zookeeper连接可以在dubbo-2.5.x\dubbo-admin\src\main\webapp\WEB-INF文件夹下的dubbo.properties中修改

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值