Dubbo 2.7.x使用

环境

代码地址dubbo-v2.7.x

dubbo 2.7.0
duboo-spring-boot-starter 2.7.0

启动 provider

访问以下地址来判断provider端使用多协议是否正常

[http://localhost:9090/top.ylonline.dubbo27x.api.RestService/single/echo?message=rest-protocol]
(http://localhost:9090/top.ylonline.dubbo27x.api.RestService/single/echo?message=rest-protocol)

[http://localhost:9090/top.ylonline.dubbo27x.api.MultipleService/multiple/echo?message=dubbo-or-rest-protocol]
(http://localhost:9090/top.ylonline.dubbo27x.api.MultipleService/multiple/echo?message=dubbo-or-rest-protocol)

使用接口的全限类名作为contextpath是dubbo-2.7.0的bug,请看issue,此PR修复了这个问题

启动 consumer

分别访问以下地址来判断consumer端使用多协议是否正常

异常问题

java.lang.NoClassDefFoundError: org/jboss/resteasy/client/jaxrs/engines/ApacheHttpClient4Engine

需要添加以下依赖包,该依赖 provider 端无需依赖,consumer 端需要依赖

1
2
3
4
5
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>${resteasy-client.version}</version>
</dependency>

java.lang.RuntimeException: You must use at least one, but no more than one http method annotation on: top.ylonline

.dubbo.spring.boot.example.api.EchoService.echo..

出现这个异常,说明要在使用的接口标注:@Path、@POST、@Get等javax.ws.rs.*这个路径下相关注解,不应该在实现类标注

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package top.ylonline.dubbo.spring.boot.api;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;

/**
* @author YL
*/
@Path("/single")
public interface RestService {
/**
* echo
*
* @param message msg
*
* @return 信息
*/
@GET
@Path("/echo")
String echo(@QueryParam("message") String message);
}

Duplicate application configs

本人提了一个issue

当使用org.apache.dubbo:dubbo-spring-boot-starter 2.7.0,同时使用xml作为dubbo的配置时,会出现以下异常:

1
Caused by: java.lang.IllegalStateException: Duplicate application configs: <dubbo:application name="dubbo-consumer-2.7.x" valid="true" id="dubbo-consumer-2.7.x" prefix="dubbo.application" /> and <dubbo:application valid="false" prefix="dubbo.application" />

main 类

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
@SpringBootApplication(
exclude = {
DataSourceAutoConfiguration.class,
WebSocketServletAutoConfiguration.class,
JmxAutoConfiguration.class
}
)
@ImportResource(locations = {"classpath:dubbo.xml"})
@Slf4j
public class DubboConsumer270 {

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

dubbo.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://dubbo.apache.org/schema/dubbo
http://dubbo.apache.org/schema/dubbo/dubbo.xsd">

<dubbo:application name="dubbo-consumer-2.7.x">
<dubbo:parameter key="qos.enable" value="false"/>
</dubbo:application>

<dubbo:registry address="zookeeper://192.168.56.101:2181" client="curator"/>

<dubbo:consumer check="false" client="netty"/>

<dubbo:reference id="dubboService"
interface="top.ylonline.dubbo27x.api.DubboService"/>
</beans>

pom.xml

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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<properties>
<dubbo.version>2.7.0</dubbo.version>
<spring-boot.version>2.0.6.RELEASE</spring-boot.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>${dubbo.version}</version>
<exclusions>
<exclusion>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</exclusion>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>${dubbo.version}</version>
</dependency>
<!-- Dubbo zookeeper registry dependency -->
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.9</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>2.12.0</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>2.12.0</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.29.Final</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>21.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
</dependencies>
</dependencyManagement>


<!-- dubbo -->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
</dependency>

<!-- zk registry dependency -->
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
</dependency>

解决方法:

  • 去掉dubbo-spring-boot-starter依赖,使用xml方式配置dubbo
  • 不使用xml方式配置dubbo,单单使用dubbo-spring-boot-starter方式

No such extension org.apache.dubbo.metadata.store.MetadataReportFactory by name redis

问题描述请看:issue

本人提交了一个PR修复了此问题

同时,也可以添加以下依赖来解决这个问题

1
2
3
4
5
6
7
8
9
10
11
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-metadata-report-redis</artifactId>
<version>2.7.0</version>
<exclusions>
<exclusion>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-metadata-report-api</artifactId>
</exclusion>
</exclusions>
</dependency>

  • 本文作者: forever杨
  • 本文链接: https://blog.yl-online.top/posts/ed805d7d.html
  • 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。如果文章内容对你有用,请记录到你的笔记中。本博客站点随时会停止服务,请不要收藏、转载!