netty使用redis发布订阅实现消息推送

netty使用redis发布订阅实现消息推送

场景

项目中需要给用户推送消息:

在这里插入图片描述

接口

@RestController
public class PushApi {@Autowiredprivate PushService pushService;/*** 消息推送* @param query* @return*/@PostMapping("/push/message")public String push(@RequestBody MessagePushConfigDto query){pushService.push(query);return "success";}}@Component
@Slf4j
public class PushService {@Autowiredprivate StringRedisTemplate redisTemplate;@Autowiredprivate MessageService messageService;public void push(MessagePushConfigDto query) {String messageNo = UUID.randomUUID().toString();if (query.getType()== Constants.MSG_TYPE_ALL){doPushGroup(query, messageNo);}else {doPushToUser(query, messageNo);}}private void doPushGroup(MessagePushConfigDto query, String messageNo) {MessageDto dto = new MessageDto();dto.setModule(query.getModule());dto.setType(query.getType());dto.setMessageNo(messageNo);dto.setContent(query.getContent());//转发至其他节点redisTemplate.convertAndSend(Constants.TOPIC_MODULE, JSON.toJSONString(dto));}private void doPushToUser(MessagePushConfigDto query, String messageNo) {for (String identityNo : query.getIdentityList()) {MessageDto dto = new MessageDto();dto.setModule(query.getModule());dto.setType(query.getType());dto.setMessageNo(messageNo);dto.setContent(query.getContent());dto.setIdentityNo(identityNo);String key = MessageFormat.format(Constants.USER_KEY, query.getModule(),identityNo);String nodeIp = redisTemplate.opsForValue().get(key);if (StrUtil.isBlank(nodeIp)){log.info("no user found: {}-{}",identityNo, key);return;}if (NodeConfig.node.equals(nodeIp)){log.info("send from local: {}", identityNo);messageService.sendToUser(dto.getMessageNo(),dto.getModule(),dto.getIdentityNo(),dto.getContent());}else {//转发至其他节点redisTemplate.convertAndSend(Constants.TOPIC_USER, JSON.toJSONString(dto));}}}
}

实体

//发送的消息
@Data
public class MessageDto {private String module;/*** 1、指定用户* 2、全部*/private Integer type;private String messageNo;private String content;private String identityNo;}//消息配置
@Data
public class MessagePushConfigDto {private String module;/*** 1、指定用户* 2、全部*/private Integer type;private String content;private List<String> identityList;}//常量
public interface Constants {int MSG_TYPE_ALL = 1;int MSG_TYPE_SINGLE = 0;String TOPIC_MODULE = "topic:module";String TOPIC_USER = "topic:module:user";String USER_KEY = "socket:module:{0}:userId:{1}";
}
MessageService 发送消息接口
public interface MessageService {/*** 发送组* @param messageNo* @param module* @param content*/void sendToGroup(String messageNo, String module, String content);/*** 单用户发送* @param messageNo* @param module* @param identityNo* @param content*/void sendToUser(String messageNo, String module, String identityNo, String content);
}public class MessageServiceImpl implements MessageService {private SessionRegistry sessionRegistry;public MessageServiceImpl(SessionRegistry sessionRegistry) {this.sessionRegistry = sessionRegistry;}@Overridepublic void sendToGroup(String messageNo, String module, String content) {SessionGroup sessionGroup = sessionRegistry.retrieveGroup(module);if (!Objects.isNull(sessionGroup)){sessionGroup.sendGroup(content);}}@Overridepublic void sendToUser(String messageNo, String module, String identityNo, String content) {WssSession wssSession = sessionRegistry.retrieveSession(module, identityNo);if (!Objects.isNull(wssSession)){wssSession.send(content);}}
}
SessionService

操作 session 服务,并设置 用户到redis

public interface SessionService<WS extends WssSession<C>,C> {/*** 添加session* @param session*/void addSession(WS session);/*** 删除session* @param session*/void removeSession(WS session);}
public abstract class AbstractSessionService<SR extends SessionRegistry<WS, C>, WS extends WssSession<C>, C>implements SessionService<WS, C> {@Getterprivate SR sessionRegistry;public AbstractSessionService(SR sessionRegistry) {this.sessionRegistry = sessionRegistry;}
}public class SessionServiceImpl<SR extends SessionRegistry<WS, C>, WS extends WssSession<C>, C>extends AbstractSessionService<SR, WS, C> {private StringRedisTemplate redisTemplate;public SessionServiceImpl(SR sessionRegistry, StringRedisTemplate redisTemplate) {super(sessionRegistry);this.redisTemplate = redisTemplate;}@Overridepublic void addSession(WS session) {getSessionRegistry().addSession(session);String key = MessageFormat.format(Constants.USER_KEY, session.getModule(), session.getIdentityNo());redisTemplate.opsForValue().set(key, NodeConfig.node);}@Overridepublic void removeSession(WS session) {getSessionRegistry().removeSession(session);String key = MessageFormat.format(Constants.USER_KEY, session.getModule(), session.getIdentityNo());redisTemplate.delete(key);}}

websocket 实现

定义session接口相关

public interface WssSession<C> {/*** 模块* @return*/String getModule();/*** 用户唯一标识* @return*/String getIdentityNo();/*** 通信渠道* @return*/C getChannel();/*** 发送消息* @param message*/void send(String message);}public interface SessionGroup <T extends WssSession<C>, C>{/*** add session* @param session*/void addSession(T session);/*** remove session* @param session*/void removeSession(T session);/*** 发送组数据* @param message*/void sendGroup(String message);/*** 根据唯一标识查询session* @param identityNo* @return*/T getSession(String identityNo);}
public interface SessionRegistry<T extends WssSession<C>, C> {/*** 添加 session** @param session*/void addSession(T session);/*** 移除 session** @param session*/void removeSession(T session);/*** 查询 SessionGroup* @param module* @return*/SessionGroup<T, C> retrieveGroup(String module);/*** 查询 session* @param module* @param identityNo* @return*/T retrieveSession(String module, String identityNo);}public abstract class AbstractSession<C> implements WssSession<C>{private String module;private String identityNo;private C channel;public AbstractSession(String module, String identityNo, C channel) {this.module = module;this.identityNo = identityNo;this.channel = channel;}@Overridepublic String getModule() {return module;}@Overridepublic String getIdentityNo() {return identityNo;}@Overridepublic C getChannel() {return channel;}
}public abstract class AbstractSessionRegistry<T extends WssSession<C>, C> implements SessionRegistry<T, C> {private Map<String, SessionGroup<T, C>> map = new ConcurrentHashMap<>();@Overridepublic void addSession(T session) {SessionGroup<T, C> sessionGroup = map.computeIfAbsent(session.getModule(), key -> newSessionGroup());sessionGroup.addSession(session);}protected abstract SessionGroup<T, C> newSessionGroup();@Overridepublic void removeSession(T session) {SessionGroup<T, C> sessionGroup = map.get(session.getModule());sessionGroup.removeSession(session);}@Overridepublic SessionGroup<T, C> retrieveGroup(String module) {return map.get(module);}@Overridepublic T retrieveSession(String module, String identityNo) {SessionGroup<T, C> sessionGroup = map.get(module);if (sessionGroup != null) {return (T) sessionGroup.getSession(identityNo);}return null;}
}

使用 netty 容器

@Slf4j
@Component
public class NettyServer {private NioEventLoopGroup boss;private NioEventLoopGroup worker;@Value("${namespace:/ns}")private String namespace;@Autowiredprivate SessionService sessionService;@PostConstructpublic void start() {try {boss = new NioEventLoopGroup(1);worker = new NioEventLoopGroup();ServerBootstrap serverBootstrap = new ServerBootstrap();serverBootstrap.group(boss, worker).channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<SocketChannel>() {@Overrideprotected void initChannel(SocketChannel ch) throws Exception {ChannelPipeline pipeline = ch.pipeline();pipeline.addLast(new IdleStateHandler(0, 0, 60));pipeline.addLast(new HeartBeatInboundHandler());pipeline.addLast(new HttpServerCodec());pipeline.addLast(new HttpObjectAggregator(64 * 1024));pipeline.addLast(new ChunkedWriteHandler());pipeline.addLast(new HttpRequestInboundHandler(namespace));pipeline.addLast(new WebSocketServerProtocolHandler(namespace, true));pipeline.addLast(new WebSocketHandShakeHandler(sessionService));}});int port = 9999;serverBootstrap.bind(port).addListener((ChannelFutureListener) future -> {if (future.isSuccess()) {log.info("server start at port successfully: {}", port);} else {log.info("server start at port error: {}", port);}}).sync();} catch (InterruptedException e) {log.error("start error", e);close();}}@PreDestroypublic void destroy() {close();}private void close() {log.info("websocket server close..");if (boss != null) {boss.shutdownGracefully();}if (worker != null) {worker.shutdownGracefully();}}}public class NettySessionGroup implements SessionGroup<NWssSession,Channel> {private ChannelGroup group = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);//Map<identityNo,channel>private Map<String, NWssSession> map = new ConcurrentHashMap<>();@Overridepublic void addSession(NWssSession session) {group.add(session.getChannel());map.put(session.getIdentityNo(), session);}@Overridepublic void removeSession(NWssSession session) {group.remove(session.getChannel());map.remove(session.getIdentityNo());}@Overridepublic void sendGroup(String message){group.writeAndFlush(new TextWebSocketFrame(message));}@Overridepublic NWssSession getSession(String identityNo) {return map.get(identityNo);}}public class NettySessionRegistry extends AbstractSessionRegistry<NWssSession, Channel> {@Overrideprotected SessionGroup<NWssSession, Channel> newSessionGroup() {return new NettySessionGroup();}
}public class NWssSession extends AbstractSession<Channel> {public NWssSession(String module, String identityNo, Channel channel) {super(module, identityNo, channel);}@Overridepublic void send(String message) {getChannel().writeAndFlush(new TextWebSocketFrame(message));}
}public class NettyUtil {//参数-module<->user-codepublic static AttributeKey<String> G_U = AttributeKey.valueOf("GU");//参数-uripublic static AttributeKey<String> P = AttributeKey.valueOf("P");/*** 设置上下文参数** @param channel* @param attributeKey* @param data* @param <T>*/public static <T> void setAttr(Channel channel, AttributeKey<T> attributeKey, T data) {Attribute<T> attr = channel.attr(attributeKey);if (attr != null) {attr.set(data);}}/*** 获取上下文参数** @param channel* @param attributeKey* @param <T>* @return*/public static <T> T getAttr(Channel channel, AttributeKey<T> attributeKey) {return channel.attr(attributeKey).get();}/*** 根据 渠道获取 session** @param channel* @return*/public static NWssSession getSession(Channel channel) {String attr = channel.attr(G_U).get();if (StrUtil.isNotBlank(attr)) {String[] split = attr.split(",");String groupId = split[0];String username = split[1];return new NWssSession(groupId, username, channel);}return null;}public static void writeForbiddenRepose(ChannelHandlerContext ctx) {String res = "FORBIDDEN";FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.FORBIDDEN, Unpooled.wrappedBuffer(res.getBytes(StandardCharsets.UTF_8)));response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/plain");response.headers().set(HttpHeaderNames.CONTENT_LENGTH, response.content().readableBytes());ctx.writeAndFlush(response);ctx.close();}}public interface WebSocketListener {void handShakeSuccessful(ChannelHandlerContext ctx, String uri);void handShakeFailed(ChannelHandlerContext ctx,String uri);
}//解析 request uri参数
@Slf4j
public class DefaultWebSocketListener implements WebSocketListener {private static final String G = "module";private static final String U = "userCode";@Overridepublic void handShakeSuccessful(ChannelHandlerContext ctx, String uri) {QueryStringDecoder decoderQuery = new QueryStringDecoder(uri);Map<String, List<String>> params = decoderQuery.parameters();String groupId = getParameter(G, params);String userCode = getParameter(U, params);if (StrUtil.isBlank(groupId) || StrUtil.isBlank(userCode)) {log.info("module or userCode is null: {}", uri);NettyUtil.writeForbiddenRepose(ctx);return;}//传递参数NettyUtil.setAttr(ctx.channel(), NettyUtil.G_U, groupId.concat(",").concat(userCode));}@Overridepublic void handShakeFailed(ChannelHandlerContext ctx, String uri) {log.info("handShakeFailed failed,close channel");ctx.close();}private String getParameter(String key, Map<String, List<String>> params) {if (CollectionUtils.isEmpty(params)) {return null;}List<String> value = params.get(key);if (CollectionUtils.isEmpty(value)) {return null;}return value.get(0);}}
netty handler
//心跳
@Slf4j
public class HeartBeatInboundHandler extends ChannelInboundHandlerAdapter {@Overridepublic void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {if (evt instanceof IdleStateEvent ise){if (ise.state()== IdleState.ALL_IDLE){//关闭连接log.info("HeartBeatInboundHandler heart beat close");ctx.channel().close();return;}}super.userEventTriggered(ctx,evt);}}/*** @Date: 2024/7/17 13:06* 处理 http 协议 的请求参数并传递*/
@Slf4j
public class HttpRequestInboundHandler extends ChannelInboundHandlerAdapter {private String namespace;public HttpRequestInboundHandler(String namespace) {this.namespace = namespace;}@Overridepublic void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {if (msg instanceof FullHttpRequest request) {//ws://localhost:8080/n/ws?groupId=xx&username=tomString requestUri = request.uri();String decode = URLDecoder.decode(requestUri, StandardCharsets.UTF_8);log.info("raw request url: {}", decode);URI uri = new URI(requestUri);if (!uri.getPath().startsWith(namespace)) {NettyUtil.writeForbiddenRepose(ctx);return;}// TODO: 2024/7/17 校验token// 比如从 header中获取token// 构建自定义WebSocket握手处理器, 也可以使用 netty自带 WebSocketServerProtocolHandler//shakeHandsIfNecessary(ctx, request, requestUri);//去掉参数 ===>  ws://localhost:8080/n/ws//传递参数NettyUtil.setAttr(ctx.channel(), NettyUtil.P, requestUri);request.setUri(namespace);ctx.pipeline().remove(this);ctx.fireChannelRead(request);}}
/*private void shakeHandsIfNecessary(ChannelHandlerContext ctx, FullHttpRequest request, String requestUri) {WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(getWebSocketLocation(request), null, true);WebSocketServerHandshaker handshaker = wsFactory.newHandshaker(request);if (handshaker == null) {// 如果不支持WebSocket版本,返回HTTP 405错误WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ctx.channel());} else {ChannelPipeline pipeline = ctx.channel().pipeline();handshaker.handshake(ctx.channel(), request).addListener((ChannelFutureListener) future -> {if (future.isSuccess()) {//握手成功 WebSocketListener listenerlistener.handShakeSuccessful(ctx, requestUri);} else {//握手失败listener.handShakeFailed(ctx, requestUri);}});}}private String getWebSocketLocation(FullHttpRequest req) {return "ws://" + req.headers().get(HttpHeaderNames.HOST) + prefix;}*/
}@Slf4j
public class WebSocketBizHandler extends SimpleChannelInboundHandler<WebSocketFrame> {private SessionService sessionService;public WebSocketBizHandler(SessionService sessionService){this.sessionService = sessionService;}@Overridepublic void handlerAdded(ChannelHandlerContext ctx) throws Exception {log.info("handlerAdded");NWssSession session = NettyUtil.getSession(ctx.channel());if (session == null) {log.info("session is null: {}", ctx.channel().id());NettyUtil.writeForbiddenRepose(ctx);return;}sessionService.addSession(session);}@Overridepublic void handlerRemoved(ChannelHandlerContext ctx) throws Exception {log.info("handlerRemoved");NWssSession session = NettyUtil.getSession(ctx.channel());if (session == null) {log.info("session is null: {}", ctx.channel().id());return;}sessionService.removeSession(session);}@Overrideprotected void channelRead0(ChannelHandlerContext ctx, WebSocketFrame msg) throws Exception {if (msg instanceof TextWebSocketFrame) {} else if (msg instanceof BinaryWebSocketFrame) {} else if (msg instanceof PingWebSocketFrame) {} else if (msg instanceof PongWebSocketFrame) {} else if (msg instanceof CloseWebSocketFrame) {if (ctx.channel().isActive()) {ctx.close();}}ctx.writeAndFlush(new TextWebSocketFrame("默认回复"));}@Overridepublic void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {//处理最后的业务异常log.info("WebSocketBizHandler error: ", cause);}
}//处理websocket协议握手
@Slf4j
public class WebSocketHandShakeHandler extends ChannelInboundHandlerAdapter {private SessionService sessionService;private WebSocketListener webSocketListener = new DefaultWebSocketListener();public WebSocketHandShakeHandler(SessionService sessionService) {this.sessionService = sessionService;}@Overridepublic void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {if (evt instanceof WebSocketServerProtocolHandler.HandshakeComplete) {log.info("WebSocketHandShakeHandler shake-hands success");// 在此处获取URL、Headers等信息并做校验,通过throw异常来中断链接。String uri = NettyUtil.getAttr(ctx.channel(), NettyUtil.P);if (StrUtil.isBlank(uri)) {log.info("request uri is null");NettyUtil.writeForbiddenRepose(ctx);return;}webSocketListener.handShakeSuccessful(ctx, uri);ChannelPipeline pipeline = ctx.channel().pipeline();pipeline.addLast(new WebSocketBizHandler(sessionService));pipeline.remove(this);return;}super.userEventTriggered(ctx, evt);}@Overridepublic void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {if (cause instanceof WebSocketHandshakeException) {//只处理 websocket 握手相关异常FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.BAD_REQUEST,Unpooled.wrappedBuffer(cause.getMessage().getBytes()));ctx.channel().writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);return;}super.exceptionCaught(ctx,cause);}}

配置

@Component
public class NodeConfig {public static String node;@PostConstructpublic void init() {String localhostStr = NetUtil.getLocalhostStr();NodeConfig.node = localhostStr;Assert.notNull(NodeConfig.node, "local ip is null");}
}@Slf4j
@Configuration
public class RedisPublishConfig {@Beanpublic RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory, MessageListener messageListener) {RedisMessageListenerContainer container = new RedisMessageListenerContainer();container.setConnectionFactory(connectionFactory);List<PatternTopic> topicList = new ArrayList<>();topicList.add(new PatternTopic(Constants.TOPIC_USER));topicList.add(new PatternTopic(Constants.TOPIC_MODULE));container.addMessageListener(messageListener, topicList);log.info("RedisMessageListenerContainer listen topic: {}", Constants.TOPIC_USER);return container;}}@Slf4j
@Component
public class RedisPublisherListener implements MessageListener {@Autowiredprivate RedisPublisherConsumer messageService;@Overridepublic void onMessage(Message message, byte[] pattern) {try {String topic = new String(pattern);String msg = new String(message.getBody(), "utf-8");log.info("recv topic:{}, msg: {}", topic, msg);messageService.consume(topic, msg);} catch (UnsupportedEncodingException e) {log.error("recv msg error: {}", new String(pattern), e);}}
}@Configuration
public class WebSocketConfig {@Beanpublic NettySessionRegistry sessionRegistry() {return new NettySessionRegistry();}@Beanpublic SessionService<NWssSession, Channel> sessionService(StringRedisTemplate redisTemplate) {return new SessionServiceImpl<>(sessionRegistry(), redisTemplate);}@Beanpublic MessageService messageService() {return new MessageServiceImpl(sessionRegistry());}}

good luck!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://xiahunao.cn/news/3266537.html

如若内容造成侵权/违法违规/事实不符,请联系瞎胡闹网进行投诉反馈,一经查实,立即删除!

相关文章

国内访问Docker Hub慢问题解决方法

在国内访问Docker Hub时可能会遇到一些困难&#xff0c;但幸运的是&#xff0c;有多种解决方案可以帮助你顺利下载Docker镜像。以下是一些有效的解决方案&#xff1a; 配置Docker镜像源&#xff1a;你可以通过配置Docker的daemon.json文件来使用国内镜像源&#xff0c;比如DaoC…

四、GD32 MCU 常见外设介绍(8)SPI 模块介绍

串行外设接口&#xff08;Serial Peripheral Interface&#xff0c;缩写为 SPI&#xff09; 提供了基于SPI 协议的数据发送和接收功能&#xff0c; 可以工作于主机或从机模式。 SPI 接口支持具有硬件 CRC 计算和校验的全双工和单工模式。 8.1.SPI 基础知识 SPI 物理层 SPI接…

【Three.js基础学习】17.imported-models

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 前言 课程回顾&#xff1a; 如何在three.js 中引入不同的模型&#xff1f; 1. 格式 &#xff08;不同的格式&#xff09; https://en.wikipedia.org/wiki/List_of_file_form…

UART编程框架详解

1. UART介绍 UART&#xff1a;通用异步收发传输器&#xff08;Universal Asynchronous Receiver/Transmitter)&#xff0c;简称串口。 调试&#xff1a;移植u-boot、内核时&#xff0c;主要使用串口查看打印信息 外接各种模块 1.1 硬件知识_UART硬件介绍 UART的全称是Unive…

Unity UGUI 之 事件接口

本文仅作学习笔记与交流&#xff0c;不作任何商业用途 本文包括但不限于unity官方手册&#xff0c;唐老狮&#xff0c;麦扣教程知识&#xff0c;引用会标记&#xff0c;如有不足还请斧正 本文在发布时间选用unity 2022.3.8稳定版本&#xff0c;请注意分别 1.什么是事件接口&…

找实习,三本计算机 > 985文科 ?

2018年3月&#xff0c;大三下学期。 写了一段时间博客以后&#xff0c;竟有人说要内推我。 我说我大三&#xff0c;还没毕业&#xff0c;准备暑假去找实习。 网上认识的朋友建议我去春招实习试试&#xff0c;还有些厂在走流程中&#xff0c;还有机会。 我婉拒了&#xff0c…

Centos 8 配置网络源

备份当前的软件源配置文件&#xff1a; sudo cp -a /etc/yum.repos.d /etc/yum.repos.d.bak 清理原有的 yum 仓库配置信息&#xff1a; sudo rm -f /etc/yum.repos.d/*.repo 获取阿里云的 CentOS 8 源配置&#xff1a; sudo curl -o /etc/yum.repos.d/CentOS-Base.repo ht…

Shell编程之正则表达式与文本处理器2--sed

目录 一、sed 工具 1. 概述 2. sed 原理 3、常用操作选项 3.1 常用选项 3.2 操作命令 4. sed 的使用 5. 具体操作 5.1 打印输出 p 5.1.1 显示范围、单行、指定行输出、指定往后加几行输出 5.1.2 显示奇偶行 5.1.3 将指定内容的行打印出来 5.1.4 只输出行号…

《python程序语言设计》第6章12题 显示字符,使用下面的函数头,编写一个打印字符的函数

def printChars(ch1, ch2, numberPerLine):a ord(ch1)b ord(ch2)count 0for i in range(a, b 1):count 1print(chr(i), end" ")if count % numberPerLine 0:print()printChars("1", "Z", 10)

UDP/TCP协议解析

我最近开了几个专栏&#xff0c;诚信互三&#xff01; > |||《算法专栏》&#xff1a;&#xff1a;刷题教程来自网站《代码随想录》。||| > |||《C专栏》&#xff1a;&#xff1a;记录我学习C的经历&#xff0c;看完你一定会有收获。||| > |||《Linux专栏》&#xff1…

FTTransformer,一个很能打的模型

FTTransformer&#xff0c;是一个BERT模型架构在结构化数据集上的迁移变体。和BERT一样&#xff0c;它非常能打。 它可能是少数能够在大多数结构化数据集上取得超过或者匹配LightGBM结果的深度模型。 本范例我们将应用它在来对Covertype植被覆盖数据集进行一个多分类任务。 我们…

k8s通过应用修改yaml文件修改容器时区

通过挂载&#xff0c;把本地的/etc/localtime挂载到容器中&#xff1a; apiVersion: apps/v1 kind: Deployment metadata:name: seb-algorithmsnamespace: jiaoda spec:replicas: 1selector:matchLabels:app: seb-algorithmstemplate:metadata:labels:app: seb-algorithmsspec…

虚幻引擎(Unreal Engine)深入探索与应用实践

目录 引言 虚幻引擎基础 引擎概述 核心组件 安装与配置 准备工作 安装步骤 常见问题 应用实践 游戏开发 影视特效 数字孪生 虚幻引擎中的C示例 如何在虚幻引擎中使用C代码 引言 虚幻引擎&#xff08;Unreal Engine&#xff0c;简称UE&#xff09;作为目前游戏开…

Ruoyi-WMS部署

所需软件 1、JDK&#xff1a;8 安装包&#xff1a;https://www.oracle.com/java/technologies/javase/javase8-archive-downloads.htmlopen in new window 安装文档&#xff1a;https://cloud.tencent.com/developer/article/1698454open in new window 2、Redis 3.0 安装包&a…

ZStack Cloud 5.1.8正式发布——GPU运维、物理机硬件监控、克隆云主机网络配置三大亮点简析

云轴科技ZStack Cloud云平台是遵循“简单、弹性、健壮、智能”的“4S”特性的私有云和无缝混合云产品。ZStack Cloud 5.1.8版本正式发布&#xff0c;从用户业务场景和实际需求出发&#xff0c;丰富和完善平台功能&#xff0c;推出一系列重要功能和多项改进&#xff0c;覆盖云主…

Oracle集群RAC磁盘管理命令asmcmd的使用

文章目录 ASM磁盘共享简介ASM磁盘共享的优势ASM磁盘组成ASM磁盘共享的应用场景Asmcmd简介Asmcmd的功能Asmcmd的命令Asmcmd的使用注意事项Asmcmd运行模式交互模式运行非交互模式运行ASMCMD命令分类实例管理命令:文件管理命令:磁盘组管理命令:模板管理命令:文件访问管理命令:…

产线工控安全新纪元:主机加固与防勒索病毒双剑合璧

在这个数字时代&#xff0c;企业面临的最大挑战之一就是如何确保数据的安全。随着勒索病毒等恶意软件的不断进化&#xff0c;传统的安全措施已经难以应对这些新型威胁。深信达公司的MCK主机加固系统&#xff0c;以其独特的内核级签名校验技术和深度学习驱动的业务场景白名单策略…

SpringMVC中的常用注解

目录 SpringMVC的定义 SpringMVC的常用注解 获取Cookie和Session SpringMVC的定义 Spring Web MVC 是基于 Servlet API 构建的原始 Web 框架&#xff0c;从⼀开始就包含在 Spring 框架中。它的正式名称“Spring Web MVC”来⾃其源模块的名称(Spring-webmvc)&#xff0c;但它…

[k8s源码]5.自己写一个informer控制器

k8s的informer控制器有一个informer&#xff0c;有一个indexer&#xff0c;还需要一个队列来存储从kubernetes API获取的信息。 初始化自己的informer的结构 type Controller struct {indexer cache.Indexerinformer cache.Controllerqueue workqueue.RateLimitingInterf…

C#基础——类

类 类是一个数据类型的蓝图。构成类的方法和变量称为类的成员&#xff0c;对象是类的实例。类的定义规定了类的对象由什么组成及在这个对象上可执行什么操作。 class 类名 { (访问属性) 成员变量; (访问属性) 成员函数; } 访问属性&#xff1a;public&#xff08;公有的&…