Dubbo based on the use of the springboot

1, the introduction jar package:

    <!-- 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, the introduction of a common jar package (jar package service provided by the producer)

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

3, producer services configuration:

## 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

Use 4, producers

   1) added to the startup class springboot of @EnableDubboConfiguration comment

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

 2) on the implementation of the interface add annotations to expose @Service service (note that dubbo of @Service, instead of spring)

5, consumer service configuration:

# 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, the use of consumer

  1) added in the same class springboot start of @EnableDubboConfiguration comment

  2) the service consumer use @Reference annotation to reference service (note that dubbo instead of spring)

 

Guess you like

Origin www.cnblogs.com/wzk-0000/p/10950736.html