Skip to content

Commit

Permalink
Dubbo Admin 入门示例
Browse files Browse the repository at this point in the history
  • Loading branch information
YunaiV committed Jun 23, 2020
1 parent 55d1b12 commit 1c04473
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 12 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@
* [《芋道 Spring Cloud 声明式调用 Feign 入门》](http://www.iocoder.cn/Spring-Cloud/Feign/?github) 对应 [labx-03](https://github.com/YunaiV/SpringBoot-Labs/tree/master/labx-03)
* [《芋道 Spring Cloud 服务网关 Spring Cloud Gateway 入门》](http://www.iocoder.cn/Spring-Cloud/Spring-Cloud-Gateway/?github) 对应 [labx-08](https://github.com/YunaiV/SpringBoot-Labs/tree/master/labx-08)
* [《芋道 Spring Cloud 链路追踪 SkyWalking 入门》](http://www.iocoder.cn/Spring-Cloud/SkyWalking/?github) 对应 [labx-14](https://github.com/YunaiV/SpringBoot-Labs/tree/master/labx-14)

* [《芋道 Dubbo Admin 快速入门》](http://www.iocoder.cn/Dubbo/Admin/?github)

# Spring Cloud 专栏

## 注册中心
Expand Down Expand Up @@ -308,9 +309,8 @@
**[CAT](http://www.iocoder.cn/CAT/install/?github)**
* [《芋道 Spring Boot 监控平台 CAT 入门》](http://www.iocoder.cn/Spring-Boot/CAT/?github)[「13. Dubbo 集成」](#)小节

TODO Dubbo-Admin

****
**[Dubbo Admin](http://www.iocoder.cn/Dubbo/Admin/?github)**
* [《芋道 Dubbo Admin 快速入门》](http://www.iocoder.cn/Dubbo/Admin/?github)

# 消息队列 MQ 专栏

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ dubbo:
# Dubbo 应用配置
application:
name: user-service-provider # 应用名
# Dubbo 注册中心配
# Dubbo 注册中心配置
registry:
address: zookeeper://127.0.0.1:2181 # 注册中心地址。个鞥多注册中心,可见 http://dubbo.apache.org/zh-cn/docs/user/references/registry/introduction.html 文档。
address: zookeeper://127.0.0.1:2181 # 注册中心地址。配置多注册中心,可见 http://dubbo.apache.org/zh-cn/docs/user/references/registry/introduction.html 文档。
# Dubbo 元数据中心配置
metadata-report:
address: zookeeper://127.0.0.1:2181 # 元数据中心地址。元数据中心的说明,可见 http://dubbo.apache.org/zh-cn/docs/user/references/metadata/introduction.html
# Dubbo 服务提供者协议配置
protocol:
port: -1 # 协议端口。使用 -1 表示随机端口。
Expand Down
1 change: 1 addition & 0 deletions lab-30/《芋道 Dubbo Admin 快速入门》.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<http://www.iocoder.cn/Dubbo/Admin/github>
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected void encode(ChannelHandlerContext ctx, Invocation invocation, ByteBuf
out.writeInt(content.length);
// 写入内容
out.writeBytes(content);
logger.info("[decode][连接({}) 编码了一条消息({})]", ctx.channel().id(), invocation.toString());
logger.info("[encode][连接({}) 编码了一条消息({})]", ctx.channel().id(), invocation.toString());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@
import io.netty.channel.SimpleChannelInboundHandler;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@ChannelHandler.Sharable
public class MessageDispatcher extends SimpleChannelInboundHandler<Invocation> {

@Autowired
private MessageHandlerContainer messageHandlerContainer;

private final ExecutorService executor = Executors.newFixedThreadPool(200);

@Override
protected void channelRead0(ChannelHandlerContext ctx, Invocation invocation) {
// 获得 type 对应的 MessageHandler 处理器
Expand All @@ -22,8 +27,15 @@ protected void channelRead0(ChannelHandlerContext ctx, Invocation invocation) {
// 解析消息
Message message = JSON.parseObject(invocation.getMessage(), messageClass);
// 执行逻辑
// noinspection unchecked
messageHandler.execute(ctx.channel(), message);
executor.submit(new Runnable() {

@Override
public void run() {
// noinspection unchecked
messageHandler.execute(ctx.channel(), message);
}

});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ public void execute(Channel channel, AuthRequest authRequest) {
return;
}

// 添加到 WebSocketUtil 中
// ... 此处应有一段

// 将用户和 Channel 绑定
// 考虑到代码简化,我们先直接使用 accessToken 作为 User
nettyChannelManager.addUser(channel, authRequest.getAccessToken());

// 判断是否认证成功。这里,假装直接成功
// 响应认证成功
AuthResponse authResponse = new AuthResponse().setCode(0);
channel.writeAndFlush(new Invocation(AuthResponse.TYPE, authResponse));
}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<!-- <module>lab-64</module>-->
<!-- <module>lab-65</module>-->
<!-- <module>lab-66</module>-->
<!-- <module>lab-67</module>-->

<!-- Spring Cloud 示例 -->
<!-- <module>labx-01</module>-->
Expand Down Expand Up @@ -110,7 +111,6 @@
<!-- <module>labx-28</module>-->
<!-- <module>labx-29</module>-->
<!-- <module>labx-30</module>-->
<module>lab-67</module>
</modules>

</project>

0 comments on commit 1c04473

Please sign in to comment.