Dubbo Admin 入门示例

This commit is contained in:
YunaiV
2020-06-23 19:20:48 +08:00
parent 55d1b125a1
commit 1c0447366b
7 changed files with 30 additions and 12 deletions

View File

@@ -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 专栏
## 注册中心
@@ -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 专栏

View File

@@ -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 表示随机端口。

View File

@@ -0,0 +1 @@
<http://www.iocoder.cn/Dubbo/Admin/github>

View File

@@ -22,7 +22,7 @@ public class InvocationEncoder extends MessageToByteEncoder<Invocation> {
out.writeInt(content.length);
// 写入内容
out.writeBytes(content);
logger.info("[decode][连接({}) 编码了一条消息({})]", ctx.channel().id(), invocation.toString());
logger.info("[encode][连接({}) 编码了一条消息({})]", ctx.channel().id(), invocation.toString());
}
}

View File

@@ -7,12 +7,17 @@ import io.netty.channel.ChannelHandlerContext;
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 处理器
@@ -22,8 +27,15 @@ public class MessageDispatcher extends SimpleChannelInboundHandler<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);
}
});
}
}

View File

@@ -25,11 +25,13 @@ public class AuthRequestHandler implements MessageHandler<AuthRequest> {
return;
}
// 添加到 WebSocketUtil 中
// ... 此处应有一段
// 将用户和 Channel 绑定
// 考虑到代码简化,我们先直接使用 accessToken 作为 User
nettyChannelManager.addUser(channel, authRequest.getAccessToken());
// 判断是否认证成功。这里,假装直接成功
// 响应认证成功
AuthResponse authResponse = new AuthResponse().setCode(0);
channel.writeAndFlush(new Invocation(AuthResponse.TYPE, authResponse));
}

View File

@@ -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>-->
@@ -110,7 +111,6 @@
<!-- <module>labx-28</module>-->
<!-- <module>labx-29</module>-->
<!-- <module>labx-30</module>-->
<module>lab-67</module>
</modules>
</project>