Skip to content

Commit

Permalink
2.3.16 dubbo proxy (#32)
Browse files Browse the repository at this point in the history
* 发布2.3.16
1.新特性:支持tcp dubbo代理
  • Loading branch information
wangzihaogithub authored May 6, 2024
1 parent 5d2ba4f commit a823be5
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 30 deletions.
38 changes: 29 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
### 简介

- 支持在一个端口号上,添加多个TCP协议,支持加自定义TCP协议
- 内置实现有: HttpServlet, RPC, MQTT, Websocket, H2, MYSQL协议.
- 内置实现有: Dubbo-proxy, HttpServlet, RPC, MQTT, Websocket, H2, MYSQL协议.
- 解决Netty在EventLoop线程里写繁忙后不返回数据的BUG.
- 解决Netty的Http遇到请求参数携带%号会报错的问题.
- 从19年开始,一直跑在作者公司某产线的线上环境运行.
Expand All @@ -27,15 +27,35 @@
server.start();


- 3.支持# http请求聚合, 然后用 select * from id in (httpRequestList).
- 3.支持# tcp dubbo代理, 解决内外网运维问题


[DubboProxy{/192.168.11.126:61184 => [pay-service//127.0.0.1:20881(UP), order-service//127.0.0.1:20881(UP)]}]

server:
port: 8080
netty:
dubbo:
enabled: true
default-service-name: 'pay-service'
services:
- service-name: 'order-service'
host: 'localhost'
port: 8082
- service-name: 'pay-service'
host: 'localhost'
port: 8082


- 4.支持# http请求聚合, 然后用 select * from id in (httpRequestList).


示例代码:com.github.netty.http.example.HttpGroupByApiController.java


- 4.支持# h2c (注: 不建议用h2,h2c当rpc, 原因在文档最底部有说明)
- 5.支持# h2c (注: 不建议用h2,h2c当rpc, 原因在文档最底部有说明)

- 5.支持# 异步零拷贝。sendFile, mmap.
- 6.支持# 异步零拷贝。sendFile, mmap.

示例代码:com.github.netty.http.example.HttpZeroCopyController.java

Expand All @@ -44,19 +64,19 @@

com.github.netty.protocol.servlet.DefaultServlet#sendFile

- 6.性能# HttpServlet比tomcat的NIO2高出25%/TPS。
- 7.性能# HttpServlet比tomcat的NIO2高出25%/TPS。

1. Netty的池化内存,减少了GC对CPU的消耗
2. Tomcat的NIO2, 注册OP_WRITE后,tomcat会阻塞用户线程等待, 并没有释放线程.
3. 与tomcat不同,支持两种IO模型,可供用户选择

- 7.性能# RPC协议略胜阿里巴巴的Dubbo(因为IO模型设计与dubbo不同,减少了线程切换)
- 8.性能# RPC协议略胜阿里巴巴的Dubbo(因为IO模型设计与dubbo不同,减少了线程切换)

- 8.特性# 单机单端口上同时提供多个TCP协议
- 9.特性# 单机单端口上同时提供多个TCP协议

- 9.特性# 支持自定义TCP协议. 如:定长传输,分隔符传输
- 10.特性# 支持自定义TCP协议. 如:定长传输,分隔符传输

- 10.特性# 支持Mysql协议代理. 如:记录mysql日志.
- 11.特性# 支持Mysql协议代理. 如:记录mysql日志.


/spring-boot-protocol/netty-mysql/zihaoapi.cn_3306-127.0.0.1_57998-packet.log
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>3.0.0</version>
<version>3.0.13</version>
<scope>provided</scope>
<optional>true</optional>
<exclusions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ protected void onBackendWriteException(ChannelHandlerContext ctx, DubboPacket pa
String backendServiceName,
Throwable cause) {
if (logger.isWarnEnabled()) {
logger.warn("onBackendWriteException {} , {}", ctx.channel(), backendClient, cause);
logger.warn("onBackendWriteException {} , {}, {}", backendServiceName, ctx.channel(), backendClient, cause);
}
this.backendException = cause;
writeProxyError(ctx, packet, Constant.SERVICE_ERROR, "dubbo proxy backend write exception! service(" + backendServiceName + ")");
Expand All @@ -104,7 +104,7 @@ protected void onBackendConnectException(ChannelHandlerContext ctx, DubboPacket
String backendServiceName,
DubboClient.DubboConnectException connectException) {
if (logger.isWarnEnabled()) {
logger.warn("onBackendConnectException {} , {}", ctx.channel(), backendClient, connectException);
logger.warn("onBackendConnectException {} , {}, {}", backendServiceName, ctx.channel(), backendClient, connectException);
}
this.backendException = connectException;
writeProxyError(ctx, packet, Constant.SERVICE_ERROR, "dubbo proxy backend connect exception! service(" + backendServiceName + "/" + backendClient.getRemoteAddress() + "(DOWN))");
Expand All @@ -115,7 +115,7 @@ protected void onBackendConnectException(ChannelHandlerContext ctx, DubboPacket
*/
protected void onBackendNonConfig(ChannelHandlerContext ctx, DubboPacket packet, String backendServiceName) {
if (logger.isWarnEnabled()) {
logger.warn("onBackendNonConfig {} , {}", ctx.channel(), packet);
logger.warn("onBackendNonConfig {} , {}, {}", backendServiceName, ctx.channel(), packet);
}
writeProxyError(ctx, packet, Constant.SERVICE_NOT_FOUND, "dubbo proxy backend non config exception! service(" + backendServiceName + ")");
}
Expand Down
5 changes: 2 additions & 3 deletions src/test/java/com/github/netty/javadubbo/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ public static void main(String[] args) throws Exception {
DemoAPI gphelloservice = (DemoAPI) classPathXmlApplicationContext.getBean("gphelloservice");
while (true) {
try {
RpcContext.getClientAttachment().setAttachment("remote.application", "order-service");
String response = gphelloservice.hello("测试",2);
String response = gphelloservice.hello("测试", 2);
System.out.println(response);
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
}
Thread.sleep(1000);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
public class DubboProxyBootstrap {

public static void main(String[] args) {
StartupServer server = new StartupServer(20880);
StartupServer server = new StartupServer(8080);
server.addProtocol(newDubboProtocol());
server.addProtocol(newHttpProtocol());
server.start();
System.out.println("浏览器访问Dubbo代理监控 : http://127.0.0.1:20880");
System.out.println("浏览器访问Dubbo代理监控 : http://127.0.0.1:8080");
}

private static DubboProtocol newDubboProtocol() {
Expand Down
1 change: 0 additions & 1 deletion src/test/java/com/github/netty/springdubbo/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public static void main(String[] args) throws Exception {
DemoAPI gphelloservice = (DemoAPI) classPathXmlApplicationContext.getBean("gphelloservice");
while (true) {
try {
RpcContext.getClientAttachment().setAttachment("remote.application", "order-service");
String response = gphelloservice.hello("测试",2);
System.out.println(response);
Thread.sleep(1000);
Expand Down
8 changes: 5 additions & 3 deletions src/test/resources/javadubbo/dubbo-client.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="dubbo-client" owner="hao"/>
<dubbo:application name="order-service" owner="hao"/>

<dubbo:registry address="N/A"/>

<dubbo:reference id="gphelloservice" interface="com.github.netty.javadubbo.example.DemoAPI"
url="dubbo://127.0.0.1:20880/com.github.netty.javadubbo.example.DemoAPI"/>
<dubbo:reference id="gphelloservice"
version="0.0.0"
interface="com.github.netty.javadubbo.example.DemoAPI"
url="dubbo://127.0.0.1:8080/com.github.netty.javadubbo.example.DemoAPI"/>

</beans>
8 changes: 5 additions & 3 deletions src/test/resources/javadubbo/dubbo-server.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

<dubbo:application name="dubbo-server" owner="hao"/>
<dubbo:application name="order-service" owner="hao"/>
<dubbo:registry address="N/A"/>

<dubbo:protocol name="dubbo" port="8081"/>
<dubbo:protocol name="dubbo" port="20881"/>

<dubbo:service interface="com.github.netty.javadubbo.example.DemoAPI" ref="gphelloservice"/>
<dubbo:service interface="com.github.netty.javadubbo.example.DemoAPI"
version="0.0.0"
ref="gphelloservice"/>

<bean id="gphelloservice" class="com.github.netty.javadubbo.example.DemoAPIImpl"/>

Expand Down
6 changes: 4 additions & 2 deletions src/test/resources/springdubbo/dubbo-client.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="dubbo-client" owner="hao"/>
<dubbo:application name="order-service" owner="hao"/>

<dubbo:registry address="N/A"/>

<dubbo:reference id="gphelloservice" interface="com.github.netty.springdubbo.example.DemoAPI"
<dubbo:reference id="gphelloservice"
version="0.0.0"
interface="com.github.netty.springdubbo.example.DemoAPI"
url="dubbo://127.0.0.1:8080/com.github.netty.springdubbo.example.DemoAPI"/>

</beans>
7 changes: 4 additions & 3 deletions src/test/resources/springdubbo/dubbo-server.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

<dubbo:application name="dubbo-server" owner="hao"/>
<dubbo:application name="order-service" owner="hao"/>
<dubbo:registry address="N/A"/>

<dubbo:protocol name="dubbo" port="8082"/>

<dubbo:service interface="com.github.netty.springdubbo.example.DemoAPI" ref="gphelloservice"/>
<dubbo:service interface="com.github.netty.springdubbo.example.DemoAPI"
version="0.0.0"
ref="gphelloservice"/>

<bean id="gphelloservice" class="com.github.netty.springdubbo.example.DemoAPIImpl"/>

Expand Down

0 comments on commit a823be5

Please sign in to comment.