OpenSource - 基于Netty的网络扩展库HServer

news/2024/7/10 21:42:12 标签: 开源, Hserver, Netty

文章目录

  • 概述
  • 官网
  • Hserver的理念
  • 特点
  • 原理图
  • 代码案例
  • HelloWorld

在这里插入图片描述


概述

HServer是一个基于Netty开发网络扩展库.使用插件方式来扩展我们的业务 HServer提供 web,gateway,rpc 等插件 同时用户也可以自定义插件,来完成各种各样的业务场景。

在这里插入图片描述


官网

https://gitee.com/HServer/HServer

https://doc.hserver.top/#/

https://gitee.com/HServer

在这里插入图片描述


Hserver_33">Hserver的理念

  • 极简、高性能、扩展强

  • 极简 代码只有几百KB

  • 高性能 使用Netty网络库作为核心,比起传统的web容器性能高数十倍.

  • 扩展强 预留了丰富的接口,以及netty直接自定义协议


特点

  • 简便易用5分钟即可掌握使用
  • 快速构建高效API
  • TCP层上直接构建
  • Restful风格路由设计
  • Cron定时器
  • Filter拦截器
  • 持久Queue队列
  • HOOK/AOP组件
  • Track链路跟踪组件
  • Web Socket功能
  • Mqtt WebSocketMqtt功能
  • 自定义协议
  • Proxy 自由处理
  • ApiDoc文档组件
  • 权限组件
  • Plugin组件自由扩展
  • HUM消息
  • 高性能
  • 高度自由度控制
  • 流量整形
  • Netty 原生响应支持自己扩展

原理图

在这里插入图片描述


代码案例

在这里插入图片描述


HelloWorld

在这里插入图片描述

建立一个maven项目,导入依赖


<parent>
    <artifactId>hserver-parent</artifactId>
    <groupId>cn.hserver</groupId>
    <version>最新版本</version>
</parent>

<dependencies>
<!--    核心依赖-->
    <dependency>
        <artifactId>hserver</artifactId>
        <groupId>cn.hserver</groupId>
    </dependency>
<!--    web框架 -->
    <dependency>
        <artifactId>hserver-plugin-web</artifactId>
        <groupId>cn.hserver</groupId>
    </dependency>
</dependencies>
<!--    打包jar -->
<build>
    <plugins>
        <plugin>
            <artifactId>hserver-plugin-maven</artifactId>
            <groupId>cn.hserver</groupId>
        </plugin>
    </plugins>
</build>

建立一个主函数

建立一个java包,如 com.test , 建立一个主函数


@HServerBoot
public class WebApp {
    public static void main(String[] args) {
        HServerApplication.run(WebApp.class, 8888, args);
    }
}

建立一个控制器


@Controller
public class HelloController {

    @GET("/test1")
    public JsonResult test() {
        return JsonResult.ok();
    }

    @POST("/test2")
    public JsonResult b(HttpRequest request) {
        return JsonResult.ok().put("data", request.getRequestParams());
    }

    @RequestMapping(value = "/get", method = RequestMethod.GET)
    public JsonResult get() {
        return JsonResult.ok();
    }

    @RequestMapping(value = "/post", method = RequestMethod.POST)
    public JsonResult post(HttpRequest httpRequest) {
        return JsonResult.ok().put("data", httpRequest.getRequestParams());
    }

    /**
     * 模板测试
     * @param httpResponse
     */
    @GET("/template")
    public void template(HttpResponse httpResponse) {
        User user = new User();
        user.setAge(20);
        user.setName("xx");
        user.setSex("男");
        Map<String, Object> obj = new HashMap<>();
        obj.put("user", user);
//        httpResponse.sendTemplate("/admin/user/list.ftl", obj);
        httpResponse.sendTemplate("a.ftl", obj);
    }
}

运行主函数,访问8888端口即可

在这里插入图片描述


http://www.niftyadmin.cn/n/5310129.html

相关文章

OpenHarmony南向之LCD显示屏

OpenHarmony南向之LCD显示屏 概述 LCD&#xff08;Liquid Crystal Display&#xff09;驱动&#xff0c;通过对显示器上下电、初始化显示器驱动IC&#xff08;Integrated Circuit&#xff09;内部寄存器等操作&#xff0c;使其可以正常工作。 HDF Display驱动模型 LCD器件驱…

使用PyTorch实现去噪扩散模型

在深入研究去噪扩散概率模型(DDPM)如何工作的细节之前&#xff0c;让我们先看看生成式人工智能的一些发展&#xff0c;也就是DDPM的一些基础研究。 VAE VAE 采用了编码器、概率潜在空间和解码器。在训练过程中&#xff0c;编码器预测每个图像的均值和方差。然后从高斯分布中对…

报文大小限制、请求体类型总结

文章目录 1. 各节点请求体有无限制1.1 http协议1.2 TCP/IP层限制1.3 浏览器1.4 nginx1.5 gateway1.6 tomcat1.7 springboot1.8 内存、磁盘处理不了一切白搭 2. 请求体类型2.1 application/x-www-form-urlencoded2.2 multipart/form-data2.3 application/json2.4 text/plain2.5 …

Ubuntu上wps调用zotero的方法

本人电脑Ubuntu22.04 克隆这位大佬的项目&#xff0c;并转到合适的目录下https://github.com/tankwyn/WPS-Zotero 输入命令 unzip WPS-Zotero-main.zip # 解压文件 cd WPS-Zotero-main # 进入目录 ./install.py # 安装文件如果上面的流程全部正常&#xff0c;恭喜成功 如果出现…

Miniconda Python解释器 Conda 包管理器 Pytorch

Miniconda Miniconda 是一个轻量级的 Anaconda 版本&#xff0c;它是一个用于管理 Python 环境和包的开源工具。Anaconda 是一个数据科学和机器学习的开发环境&#xff0c;它包含了许多常用的 Python 包和工具。 与 Anaconda 相比&#xff0c;Miniconda 的安装包更小&#xf…

Mockito+junit5搞定单元测试

目录 一、简介1.1 单元测试的特点1.2 Mock类框架的使用场景1.3 常见的Mock框架1.3.1 Mockito1.3.2 EasyMock1.3.3 PowerMock1.3.4 Testable1.3.5 比较 二、Mockito的使用2.1 导入pom文件2.2 mock对象和spy对象2.3 初始化mock/spy对象的方式2.4 参数匹配2.5 方法插桩2.6 InjectM…

Python:类型标注解决循环引用问题most likely due to a circular import

两个模块&#xff0c;我们需要做类型标注&#xff0c;于是出现了循环引用的问题 # models.py from controllers import BookControllerclass Book:def get_controller(self) -> BookController:return BookController(self)# controllers.py from models import Bookclass …

动态路由协议的配置

实验题目 动态路由协议的配置 实验目的 1) 熟悉路由器工作原理和机制&#xff1b; 2) 巩固动态路由理论&#xff1b; 3) 设计简单网络结构&#xff1b; 4) 规划IP地址、子网掩码和网关。 实验任务 1) 设计网络拓扑结构&#xff1b; 2) 正确规划IP地址、子网掩码和网关…