All Projects → cdapio → Netty Http

cdapio / Netty Http

Licence: apache-2.0
Netty based HTTP service with JAX-RS

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Netty Http

Springboot im
使用springboot + nettysocketio开发的一个简易卡牌游戏。主要想了解游戏服务端开发流程,基本逻辑等相关知识和长连接。
Stars: ✭ 94 (-13.76%)
Mutual labels:  netty
Rexlin600.github.io
系列博客、涵盖领域广、不定时更新、欢迎加入
Stars: ✭ 102 (-6.42%)
Mutual labels:  netty
Reactor Netty
TCP/HTTP/UDP/QUIC client/server with Reactor over Netty
Stars: ✭ 1,743 (+1499.08%)
Mutual labels:  netty
T Io
解决其它网络框架没有解决的用户痛点,让天下没有难开发的网络程序
Stars: ✭ 1,331 (+1121.1%)
Mutual labels:  netty
Dapeng Soa
A lightweight, high performance micro-service framework
Stars: ✭ 101 (-7.34%)
Mutual labels:  netty
Jt808 Netty
Netty入门教学项目,解析JT808协议,整合Spring boot,并提供了一些Netty中的最佳实践
Stars: ✭ 104 (-4.59%)
Mutual labels:  netty
Async Gamequery Lib
A high-performance java game query library designed for steam/source based games and others
Stars: ✭ 88 (-19.27%)
Mutual labels:  netty
Face2face
基于netty的异步非阻塞实时聊天(IM)服务器。
Stars: ✭ 1,468 (+1246.79%)
Mutual labels:  netty
Momo Cloud Permission
基于SpringBoot2.x、SpringCloud和SpringCloudAlibaba并采用前后端分离的企业级微服务多租户、多系统的系统架构。适合学习和企业中使用。真正实现了手撸RBAC、jwt的无状态统一权限认证的解决方案,面向互联网设计同时适合B端和C端用户,支持CI/CD多环境部署;同时还集合各种微服务治理功能和监控功能。模块包括:企业级的认证系统、开发平台、应用监控、慢sql监控、统一日志、单点登录、Redis分布式高速缓存、接口文档、蚂蚁金服代码生成器等等!netty心跳服务器支持鉴权、断线重连、其他业务模块开发
Stars: ✭ 101 (-7.34%)
Mutual labels:  netty
Rpc Fromscratch
🌈 从零开始设计一个轻量级分布式 RPC 框架,基于 Spring + Netty + Protostuff + Zookeeper
Stars: ✭ 106 (-2.75%)
Mutual labels:  netty
Jackson Jaxrs Providers
Multi-module project that contains Jackson-based JAX-RS providers for JSON, XML, YAML, Smile, CBOR formats
Stars: ✭ 98 (-10.09%)
Mutual labels:  jax-rs
Jupiter
Jupiter是一款性能非常不错的, 轻量级的分布式服务框架
Stars: ✭ 1,372 (+1158.72%)
Mutual labels:  netty
Easymodbus4j
easymodbus4j是一个高性能和易用的 Modbus 协议的 Java 实现,基于 Netty 开发,可用于 Modbus协议的Java客户端和服务器开发, A high-performance and ease-of-use implementation of the Modbus protocol written in Java netty support for modbus 4 mode..
Stars: ✭ 104 (-4.59%)
Mutual labels:  netty
Nitmproxy
Proxy server based on netty
Stars: ✭ 94 (-13.76%)
Mutual labels:  netty
Jetlinks Community
JetLinks 基于Java8,Spring Boot 2.x ,WebFlux,Netty,Vert.x,Reactor等开发, 是一个全响应式的企业级物联网平台。支持统一物模型管理,多种设备,多种厂家,统一管理。统一设备连接管理,多协议适配(TCP,MQTT,UDP,CoAP,HTTP等),屏蔽网络编程复杂性,灵活接入不同厂家不同协议等设备。实时数据处理,设备告警,消息通知,数据转发。地理位置,数据可视化等。能帮助你快速建立物联网相关业务系统。
Stars: ✭ 2,405 (+2106.42%)
Mutual labels:  netty
Jrestless
Run JAX-RS applications on AWS Lambda using Jersey. Supports Spring 4.x. The serverless framework can be used for deployment.
Stars: ✭ 93 (-14.68%)
Mutual labels:  jax-rs
Simple Rpc
RPC with service discovery base on netty
Stars: ✭ 103 (-5.5%)
Mutual labels:  netty
Tesla
Tesla is a gateway service that provides dynamic routing,waf,support spring cloud,gRPC,DUBBO and more.
Stars: ✭ 109 (+0%)
Mutual labels:  netty
Netty Rest
Yet another high performance REST server based on Netty
Stars: ✭ 107 (-1.83%)
Mutual labels:  netty
Httpproxy
http代理,支持CONNECT和普通GET/POST,支持http2;可防止主动嗅探;可作为小火箭、圈、surge等软件和SwitchyOmega(chrome插件)所说的https代理
Stars: ✭ 104 (-4.59%)
Mutual labels:  netty

netty-http

A library to develop HTTP services with Netty <http://netty.io/>. Supports the capability to route end-points based on JAX-RS <https://jax-rs-spec.java.net/>-style annotations. Implements Guava's Service interface to manage the runtime-state of the HTTP service.

Need for this library

Netty <http://netty.io/>__ is a powerful framework to write asynchronous event-driven high-performance applications. While it is relatively easy to write a RESTful HTTP service using netty, the mapping between HTTP routes to handlers is not a straight-forward task.

Mapping the routes to method handlers requires writing custom channel handlers and a lot of boilerplate code as well as knowledge of Netty's internals in order to correctly chain different handlers. The mapping could be error-prone and tedious when a service handles many end-points.

This library solves these problems by using JAX-RS <https://jax-rs-spec.java.net/>__ annotations to build a path routing layer on top of Netty.

Build the HTTP Library

::

$ git clone https://github.com/cdapio/netty-http.git $ cd netty-http $ mvn clean package

Setting up an HTTP Service using the Library

Setting up an HTTP service is very simple using this library:

  • Implement handler methods for different HTTP requests
  • Annotate the routes for each handler
  • Use a builder to setup the HTTP service

Example: A simple HTTP service that responds to the /v1/ping endpoint can be setup as:

.. code:: java

// Set up Handlers for Ping public class PingHandler extends AbstractHttpHandler { @Path("/v1/ping") @GET public void testGet(HttpRequest request, HttpResponder responder){ responder.sendString(HttpResponseStatus.OK, "OK"); } }

// Setup HTTP service and add Handlers

// You can either add varargs of HttpHandler or as a list of HttpHanlders as below to the NettyService Builder

List handlers = new ArrayList<>(); handlers.add(new PingHandler()); handlers.add(...otherHandler...)

NettyHttpService service = NettyHttpService.builder("Name_of_app") .setPort(7777) // Optionally set the port. If unset, it will bind to an ephemeral port .setHttpHandlers(handlers) .build();

// Start the HTTP service service.start();

Example: Sample HTTP service that manages an application lifecycle:

.. code:: java

// Set up handlers // Setting up Path annotation on a class level will be pre-pended with @Path("/v1/apps") public class ApplicationHandler extends AbstractHandler {

// The HTTP endpoint v1/apps/deploy will be handled by the deploy method given below
@Path("deploy")
@POST
public void deploy(HttpRequest request, HttpResponder responder) {
  // ..
  // Deploy application and send status
  // ..
  responder.sendStatus(HttpResponseStatus.OK);
}

// For deploying larger-size applications we can use the BodyConsumer abstract-class,
// we can handle the chunks as we receive it
// and handle clean up when we are done in the finished method, this approach is memory efficient
@Path("deploybig")
@POST
public BodyConsumer deployBig(HttpRequest request, HttpResponder responder) {
  return new BodyConsumer() {
    @Override
    public void chunk(ChannelBuffer request, HttpResponder responder) {
      // write the incoming data to a file
    }
    @Override
    public void finished(HttpResponder responder) {
      //deploy the app and send response
      responder.sendStatus(HttpResponseStatus.OK);
    }
    @Override
    public void handleError(Throwable cause) {
      // if there were any error during this process, this will be called.
      // do clean-up here.
    }
  }
}

// The HTTP endpoint v1/apps/{id}/start will be handled by the start method given below
@Path("{id}/start")
@POST
public void start(HttpRequest request, HttpResponder responder, @PathParam("id") String id) {
  // The id that is passed in HTTP request will be mapped to a String via the PathParam annotation
  // ..
  // Start the application
  // ..
  responder.sendStatus(HttpResponseStatus.OK);
}

// The HTTP endpoint v1/apps/{id}/stop will be handled by the stop method given below
@Path("{id}/stop")
@POST
public void stop(HttpRequest request, HttpResponder responder, @PathParam("id") String id) {
  // The id that is passed in HTTP request will be mapped to a String via the PathParam annotation
  // ..
  // Stop the application
  // ..
  responder.sendStatus(HttpResponseStatus.OK);
}

// The HTTP endpoint v1/apps/{id}/status will be handled by the status method given below
@Path("{id}/status")
@GET
public void status(HttpRequest request, HttpResponder responder, @PathParam("id") String id) {
  // The id that is passed in HTTP request will be mapped to a String via the PathParam annotation
  // ..
  // Retrieve status the application
  // ..
  JsonObject status = new JsonObject();
  status.addProperty("status", "RUNNING");
  responder.sendJson(HttpResponseStatus.OK, status.toString());
}

}

// Setup HTTP service and add Handlers

// You can either add varargs of HttpHandler or as a list of HttpHanlders as below to the NettyService Builder

List<HttpHandler> handlers = new ArrayList<>();
handlers.add(new PingHandler());
handlers.add(...otherHandler...)

NettyHttpService service = NettyHttpService.builder("Name_of_app") .setPort(7777) .setHttpHandlers(handlers) .build();

// Start the HTTP service service.start();

Setting up an HTTPS Service

To run an HTTPS Service, add an additional function call to the builder::

enableSSL(File:keyStore, String:keyStorePassword, String:certificatePassword)

Code Sample:

.. code:: java

// Setup HTTPS service and add Handlers NettyHttpService service = NettyHttpService.builder() .setPort(7777) .addHttpHandlers(new ApplicationHandler()) .enableSSL(SSLConfig.builder(new File("/path/to/keyStore.jks", "keyStorePassword") .setCertificatePassword("certificatePassword").build()) .build();

  • Set String:certificatePassword as "null" when not applicable
  • File:keyStore points to the key store that holds your SSL certificate

References

  • Guava <https://code.google.com/p/guava-libraries/>__
  • Jersey <https://jersey.java.net>__
  • Netty <http://netty.io/>__

Contributing to netty-http

Are you interested in making netty-http better? Our development model is a simple pull-based model with a consensus building phase, similar to the Apache's voting process. If you want to help make netty-http better, by adding new features, fixing bugs, or even suggesting improvements to something that's already there, here's how you can contribute:

  • Fork netty-http into your own GitHub repository
  • Create a topic branch with an appropriate name
  • Work on your favorite feature to your content
  • Once you are satisfied, create a pull request by going to the cdapio/netty-http project.
  • Address all the review comments
  • Once addressed, the changes will be committed to the cdapio/netty-http repo.

License

Copyright © 2014-2019 Cask Data, Inc. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].