zoukankan      html  css  js  c++  java
  • SpringBoot整合Dubbo+zookeeper

    docker pull zookeeper

    docker run --name zk01 -p 2181:2181 --restart always -d 2e30cac00aca

     表明zookeeper已成功启动


    Zookeeper和Dubbo
    • ZooKeeper
    ZooKeeper 是一个分布式的,开放源码的分布式应用程序协调服务。它是
    一个为分布式应用提供一致性服务的软件,提供的功能包括:配置维护、
    域名服务、分布式同步、组服务等。
    • Dubbo
    Dubbo是Alibaba开源的分布式服务框架,它最大的特点是按照分层的方
    式来架构,使用这种方式可以使各个层之间解耦合(或者最大限度地松耦
    合)。从服务模型的角度来看,Dubbo采用的是一种非常简单的模型,要
    么是提供方提供服务,要么是消费方消费服务,所以基于这一点可以抽象
    出服务提供方(Provider)和服务消费方(Consumer)两个角色。
     

     

    客户端(consumer)配置:

    启动类

    @SpringBootApplication
    public class ConsumerManagerApplication {

    public static void main(String[] args) {
    SpringApplication.run(ConsumerManagerApplication.class, args);
    }

    }

    controller

    @RestController
    public class ManagerController {

    @Reference
    ManagerService managerService;

    @RequestMapping("/hello")
    public String hello() {
    return managerService.hello();
    }

    }

    service(只需要跟服务类的接口一致就行,包名也要一致)

    public interface ManagerService {
    public String hello();
    }

    application.properties

    dubbo.application.name=consumer-manager
    dubbo.registry.address=zookeeper://192.168.0.106:2181
    server.port=8081

    服务端(provider)配置:

    启动类

    @SpringBootApplication
    public class ProviderManagerApplication {

    public static void main(String[] args) {
    SpringApplication.run(ProviderManagerApplication.class, args);
    }

    }

    service接口和实现类

    public interface ManagerService {
    public String hello();
    }

    @Service
    public class ManagerServiceImpl implements ManagerService {

    @Override
    public String hello() {
    System.out.println("客户端请求进来了!");
    return "xixi success !!!";
    }
    }

    application.properties

    dubbo.application.name=provider-manager
    dubbo.registry.address=zookeeper://192.168.0.106:2181
    dubbo.scan.base-packages=com.hourui

    浏览器访问:
  • 相关阅读:
    第一个EJB示例
    Visual Studio/Eclipse调用 JBoss5中的WebService
    TomEE
    eclipse 启动时使用指定的jdk
    Haskell示例
    安装VS2010 SP1后,再安装mvc3
    Mysql报错为1366的错误的时候
    Java8-如何将List转变为逗号分隔的字符串
    IDEA连接mysql又报错!Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' prope
    he last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
  • 原文地址:https://www.cnblogs.com/liuyi13535496566/p/12343208.html
Copyright © 2011-2022 走看看