• 基于springboot的Dubbo的常规总结


    1、引入jar包:

        <!-- Spring Boot Dubbo 依赖 -->
            <dependency>
                <groupId>com.alibaba.spring.boot</groupId>
                <artifactId>dubbo-spring-boot-starter</artifactId>
                <version>2.0.0</version>
            </dependency>
            <dependency>
                <groupId>org.apache.zookeeper</groupId>
                <artifactId>zookeeper</artifactId>
                <version>3.4.13</version>
            </dependency>    
    View Code

    2、引入公共的jar包(服务生产者提供的jar包)

            <!-- 引用akucun-api -->
            <dependency>
                <groupId>com.akucun</groupId>
                <artifactId>akucun-api</artifactId>
                <version>${akucun-api.version}</version>
            </dependency>    
    View Code

    3、生产者服务的配置:

    ## dubbo springboot 配置
    spring.dubbo.application.id=live-dubbo-provider
    spring.dubbo.application.name=live-dubbo-provider
    spring.dubbo.registry.address=zookeeper://127.0.0.1:2181
    spring.dubbo.server=true
    spring.dubbo.protocol.name=dubbo
    spring.dubbo.protocol.port=20880
    View Code

    4、生产者的使用

       1)在springboot的启动类添加@EnableDubboConfiguration注解

    @EnableDubboConfiguration
    @SpringBootApplication
    public class DubboServerApplication {
    public static void main(String[] args) {
            SpringApplication.run(DubboServerApplication.class, args);
        }
    }
    View Code

     2)在接口的实现上加@Service注解来暴露服务(注意是dubbo的@Service,而不是spring的)

    5、消费者服务配置:

    # dubbo
    spring.dubbo.application.name=delivery-v2
    spring.dubbo.registry.protocol=zookeeper
    spring.dubbo.registry.address=172.19.1.161:2181,172.19.1.162:2181,172.19.1.163:2181
    spring.dubbo.protocol.name=dubbo
    spring.dubbo.consumer.version=1.0.0
    spring.dubbo.consumer.check=false

    6、消费者的使用

      1)同样在springboot的启动类添加@EnableDubboConfiguration注解

      2)服务消费方使用@Reference注解来引用服务(注意是dubbo的,而不是spring的)

  • 相关阅读:
    一道编程面试题
    AtCoder Grand Contest 016 B
    AtCoder Regular Contest 076 D
    Codeforces Round #419 (Div. 2) B. Karen and Coffee
    2017 计蒜之道 复赛 Windows画图+百度地图导航
    Codeforces Round #418 (Div. 2) B. An express train to reveries
    棠梨煎雪
    Bits And Pieces
    Let Them Slide
    TeaTree
  • 原文地址:https://www.cnblogs.com/wzk-0000/p/10950736.html
Copyright © 2020-2023  润新知