All Projects → TogetherOS → Cicada

TogetherOS / Cicada

Licence: apache-2.0
🚀 Fast lightweight HTTP service framework.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Cicada

Servicestack.text
.NET's fastest JSON, JSV and CSV Text Serializers
Stars: ✭ 1,157 (+35.96%)
Mutual labels:  json, high-performance
Xproxy
reverse proxy implement in java
Stars: ✭ 20 (-97.65%)
Mutual labels:  high-performance, netty4
Nano
Lightweight, facility, high performance golang based game server framework
Stars: ✭ 1,888 (+121.86%)
Mutual labels:  json, lightweight
Cms
GleezCMS - A Light, Simple, Flexible Content Management System
Stars: ✭ 200 (-76.5%)
Mutual labels:  lightweight, high-performance
Jsoniter Scala
Scala macros for compile-time generation of safe and ultra-fast JSON codecs
Stars: ✭ 410 (-51.82%)
Mutual labels:  json, high-performance
Flexml
🚀基于Litho的Android高性能动态业务容器。
Stars: ✭ 225 (-73.56%)
Mutual labels:  lightweight, high-performance
DovakinMQ
MQTT broker for java based on Netty
Stars: ✭ 14 (-98.35%)
Mutual labels:  lightweight, netty4
Tesla
Tesla is a gateway service that provides dynamic routing,waf,support spring cloud,gRPC,DUBBO and more.
Stars: ✭ 161 (-81.08%)
Mutual labels:  high-performance, netty4
Json
An efficient JSON decoder
Stars: ✭ 260 (-69.45%)
Mutual labels:  json, high-performance
webgui
Web Technologies based Crossplatform GUI Framework with Dark theme
Stars: ✭ 81 (-90.48%)
Mutual labels:  lightweight, high-performance
Smtpd
A Lightweight High Performance ESMTP email server
Stars: ✭ 175 (-79.44%)
Mutual labels:  lightweight, high-performance
Dsl Json
High performance JVM JSON library
Stars: ✭ 706 (-17.04%)
Mutual labels:  json, high-performance
Easylogger
An ultra-lightweight(ROM<1.6K, RAM<0.3k), high-performance C/C++ log library. | 一款超轻量级(ROM<1.6K, RAM<0.3k)、高性能的 C/C++ 日志库
Stars: ✭ 1,968 (+131.26%)
Mutual labels:  lightweight, high-performance
Libaco
A blazing fast and lightweight C asymmetric coroutine library 💎 ⛅🚀⛅🌞
Stars: ✭ 2,918 (+242.89%)
Mutual labels:  lightweight, high-performance
Katwebx
An extremely fast static web server and reverse proxy for the modern web.
Stars: ✭ 39 (-95.42%)
Mutual labels:  lightweight, high-performance
Jsontreeviewer
json formatter/viewer/pretty-printer (with jsonTree javascript-library)
Stars: ✭ 211 (-75.21%)
Mutual labels:  json, lightweight
Jupiter
Jupiter是一款性能非常不错的, 轻量级的分布式服务框架
Stars: ✭ 1,372 (+61.22%)
Mutual labels:  high-performance, netty4
today-web
😐 A Java library for building web applications
Stars: ✭ 33 (-96.12%)
Mutual labels:  lightweight, high-performance
Servicestack
Thoughtfully architected, obscenely fast, thoroughly enjoyable web services for all
Stars: ✭ 4,976 (+484.72%)
Mutual labels:  json, high-performance
Jingo
This package provides the ability to encode golang structs to a buffer as JSON very quickly.
Stars: ✭ 715 (-15.98%)
Mutual labels:  json, high-performance


Introduction

Fast, lightweight Web framework based on Netty; without too much dependency, and the core jar package is only 30KB.

If you are interested, please click Star.

Features

Quick Start

Create a project with Maven, import core dependency.

<dependency>
    <groupId>top.crossoverjie.opensource</groupId>
    <artifactId>cicada-core</artifactId>
    <version>x.y.z</version>
</dependency>

Of course, it is recommended to introduce an additional IOC container plugin:

<dependency>
    <groupId>top.crossoverjie.opensource</groupId>
    <artifactId>cicada-ioc</artifactId>
    <version>2.0.4</version>
</dependency>

start class:

public class MainStart {

    public static void main(String[] args) throws InterruptedException {
        CicadaServer.start(MainStart.class,"/cicada-example") ;
    }
}

Configuring Business Action

@CicadaAction("routeAction")
public class RouteAction {

    private static final Logger LOGGER = LoggerBuilder.getLogger(RouteAction.class);


    @CicadaRoute("getUser")
    public void getUser(DemoReq req){

        LOGGER.info(req.toString());
        WorkRes<DemoReq> reqWorkRes = new WorkRes<>() ;
        reqWorkRes.setMessage("hello =" + req.getName());
        CicadaContext.getContext().json(reqWorkRes) ;
    }

    @CicadaRoute("getInfo")
    public void getInfo(DemoReq req){

        WorkRes<DemoReq> reqWorkRes = new WorkRes<>() ;
        reqWorkRes.setMessage("getInfo =" + req.toString());
        CicadaContext.getContext().json(reqWorkRes) ;
    }

    @CicadaRoute("getReq")
    public void getReq(CicadaContext context,DemoReq req){

        WorkRes<DemoReq> reqWorkRes = new WorkRes<>() ;
        reqWorkRes.setMessage("getReq =" + req.toString());
        context.json(reqWorkRes) ;
    }



}

Launch and apply access: http://127.0.0.1:5688/cicada-example/routeAction/getUser?id=1234&name=zhangsan

{"message":"hello =zhangsan"}

Cicada Context

Through context.json(), context.text(), you can choose different response ways.

@CicadaAction("routeAction")
public class RouteAction {

    private static final Logger LOGGER = LoggerBuilder.getLogger(RouteAction.class);

    @CicadaRoute("getUser")
    public void getUser(DemoReq req){

        LOGGER.info(req.toString());
        WorkRes<DemoReq> reqWorkRes = new WorkRes<>() ;
        reqWorkRes.setMessage("hello =" + req.getName());
        CicadaContext.getContext().json(reqWorkRes) ;
    }
    
    @CicadaRoute("hello")
    public void hello() throws Exception {
        CicadaContext context = CicadaContext.getContext();

        String url = context.request().getUrl();
        String method = context.request().getMethod();
        context.text("hello world url=" + url + " method=" + method);
    }    


}

Cookie Support

Set Cookie

Cookie cookie = new Cookie() ;
cookie.setName("cookie");
cookie.setValue("value");
CicadaContext.getResponse().setCookie(cookie);

Get Cookie

Cookie cookie = CicadaContext.getRequest().getCookie("cookie");
logger.info("cookie = " + cookie.toString());

Custom configuration

By default, the configuration file under the classpath is read.

You can also customize the configuration file.

Just need to extends top.crossoverjie.cicada.server.configuration.AbstractCicadaConfiguration class.

Write the name of the configuration file at the same time.

Like this:

public class RedisConfiguration extends AbstractCicadaConfiguration {


    public RedisConfiguration() {
        super.setPropertiesName("redis.properties");
    }

}

public class KafkaConfiguration extends AbstractCicadaConfiguration {

    public KafkaConfiguration() {
        super.setPropertiesName("kafka.properties");
    }


}

Get configuration information

Get the configuration infomation, follow this:

KafkaConfiguration configuration = (KafkaConfiguration) getConfiguration(KafkaConfiguration.class);
RedisConfiguration redisConfiguration = (RedisConfiguration) ConfigurationHolder.getConfiguration(RedisConfiguration.class);
ApplicationConfiguration applicationConfiguration = (ApplicationConfiguration) ConfigurationHolder.getConfiguration(ApplicationConfiguration.class);

String brokerList = configuration.get("kafka.broker.list");
String redisHost = redisConfiguration.get("redis.host");
String port = applicationConfiguration.get("cicada.port");

LOGGER.info("Configuration brokerList=[{}],redisHost=[{}] port=[{}]",brokerList,redisHost,port);

External configuration file

Configuration files can also be read in multiple environments, just add VM parameters, also ensure that the parameter name and file name are consistent.

-Dapplication.properties=/xx/application.properties
-Dkafka.properties=/xx/kakfa.properties
-Dredis.properties=/xx/redis.properties

Custom interceptor

Implement top.crossoverjie.cicada.example.intercept.CicadaInterceptor interface.

@Interceptor(value = "executeTimeInterceptor")
public class ExecuteTimeInterceptor implements CicadaInterceptor {

    private static final Logger LOGGER = LoggerBuilder.getLogger(ExecuteTimeInterceptor.class);

    private Long start;

    private Long end;

    @Override
    public boolean before(Param param) {
        start = System.currentTimeMillis();
        return true;
    }

    @Override
    public void after(Param param) {
        end = System.currentTimeMillis();

        LOGGER.info("cast [{}] times", end - start);
    }
}

Custom exception handle

You can define global exception handle,like this:

@CicadaBean
public class ExceptionHandle implements GlobalHandelException {
    private final static Logger LOGGER = LoggerBuilder.getLogger(ExceptionHandle.class);

    @Override
    public void resolveException(CicadaContext context, Exception e) {
        LOGGER.error("Exception", e);
        WorkRes workRes = new WorkRes();
        workRes.setCode("500");
        workRes.setMessage(e.getClass().getName());
        context.json(workRes);
    }
}

Performance Test

Test Conditions: 100 threads and 100 connections ;1G RAM/4 CPU

Nearly 10W requests per second.

ChangeLog

v2.0.2

  • fix #40
  • add global handle exception interface.
  • get bean by class type.

v2.0.1

  • Logo.
  • Cookie Support.
  • Beautify the log.

v2.0.0

  • Fixed #12 #22 #28
  • Flexible routing ways.
  • Pluggable IOC beanFactory.

v1.0.3

  • Fixed #9
  • Fixed #8,Multiple response ways.
  • Refactoring core code and add Cicada Context.
  • Elegant closing service.

v1.0.2

  • Fixed #6
  • Customize the configuration file.
  • Using flexible.
  • Refactor the code.

Contact author

crossoverJie#gmail.com

qrcode_for_gh_3a954a025f10_258.jpg

Special thanks

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].