Dubbo基础使用

依赖

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>${dubbo.version}</version>
</dependency>

<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>${dubbo.version}</version>
</dependency>


<!-- https://mvnrepository.com/artifact/org.apache.curator/curator-framework -->
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>4.2.0</version>
</dependency>

<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>4.2.0</version>
<exclusions>
<exclusion>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.14</version>
</dependency>
</dependencies>

Provider

1
2
3
4
5
6
7
8
9
10
server.port=8081

spring.application.name=DemoProvider
dubbo.scan.base-packages=com.midkuro.service

dubbo.protocol.name=dubbo
dubbo.protocol.port=666
dubbo.protocol.host=192.168.101.106

dubbo.registry.address=zookeeper://192.168.150.13:2181
1
2
3
4
//服务接口
public interface DemoService {
String sayHello(String name);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import org.apache.dubbo.config.annotation.Service;
import org.springframework.stereotype.Component;

//version : 接口版本
@Service(version = "1.0.0" ,timeout = 10000, interfaceClass = DemoService.class)
@Component
public class DemoServiceImpl implements DemoService {

@Override
public String sayHello(String name) {
System.out.println("来啦~~~!");
return "hello:" + name;
}
}

Consumer

1
2
3
4
spring.application.name=DemoCustomer
dubbo.scan.base-packages=com.midkuro.service

dubbo.registry.address=zookeeper://192.168.150.13:2181
1
2
3
public interface DemoService {
String sayHello(String name);
}
1
2
3
//注入使用
@Reference(version = "1.0.0")
DemoService serv;

最后更新: 2021年02月03日 15:23

原始链接: https://midkuro.gitee.io/2020/06/30/apache-dubbo/

× 请我吃糖~
打赏二维码