SpringBoot整和Dubbo+Zookeeper

Dubbo+Zookeeper依赖

<!--dubbo-->
        <!-- Dubbo Spring Boot Starter -->
        <dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo-spring-boot-starter</artifactId>
            <version>2.7.3</version>
        </dependency>
        <!--zookeeper-->
        <!-- https://mvnrepository.com/artifact/com.github.sgroschupf/zkclient -->
        <dependency>
            <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>4.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.curator</groupId>
            <artifactId>curator-recipes</artifactId>
            <version>4.0.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>

服务者代码
yml


server:
 port: 8086
dubbo:
 application:
  name: firstone   #暴露服务的名字
 registry: #连接的zookeeper地址
  address: zookeeper://192.168.93.131:2181
 ##协议端口
 protocol:
  name: dubbo
  port: 20880
 scan: ##扫描路径,改成自己@Service那个包
  base-packages: com.xiao.dubboprovider

实现类代码

@Service // 注意使用dubbo
public class TestInterfaceImpl implements TestInterface {
    @Override
    public void ins() {
        System.out.println("insert");
    }

    @Override
    public void sel() {
        System.out.println("select");
    }

    @Override
    public void del() {
        System.out.println("delete");
    }

    @Override
    public void upd() {
        System.out.println("update");
    }
}

消费者代码
yml

server:
 port: 8088
dubbo:
 application:
  name: firstwo
  #注册中心
 registry:
  address: zookeeper://192.168.93.131:2181
 scan: ##扫描路径,改成自己@Service那个包
  base-packages: com.xiao.consumer

java


@RestController
@RequestMapping("/test")
public class TestController {

    @Reference
    private TestInterface testInterface;

    @RequestMapping("/dubbo")
    public void testController(){
        testInterface.upd();
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值