close
Skip to content

chcong143231/cicada

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Image

Build Status Image QQ群


中文文档


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

  • Clean code, without too much dependency.
  • One line of code to start the HTTP service.
  • Custom interceptor.
  • Flexible parameters way.
  • Response json.
  • Start with jar.
  • Custom configuration.
  • Multiple routing ways.
  • Support HTTPS.
  • Support Cookie.
  • File Upload.

Quick Start

Create a project with Maven, import core dependency.

<dependency>
    <groupId>top.crossoverjie.opensource</groupId>
    <artifactId>cicada-core</artifactId>
    <version>1.0.1</version>
</dependency>

start class:

public class MainStart {

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

Configuring business Action

Create business Action implement top.crossoverjie.cicada.server.action.WorkAction interface:

@CicadaAction(value = "demoAction")
public class DemoAction implements WorkAction {


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

    private static AtomicLong index = new AtomicLong() ;

    @Override
    public WorkRes<DemoResVO> execute(Param paramMap) throws Exception {
        String name = paramMap.getString("name");
        Integer id = paramMap.getInteger("id");
        LOGGER.info("name=[{}],id=[{}]" , name,id);

        DemoResVO demoResVO = new DemoResVO() ;
        demoResVO.setIndex(index.incrementAndGet());
        WorkRes<DemoResVO> res = new WorkRes();
        res.setCode(StatusEnum.SUCCESS.getCode());
        res.setMessage(StatusEnum.SUCCESS.getMessage());
        res.setDataBody(demoResVO) ;
        return res;
    }

}

Launch and apply access: http://127.0.0.1:7317/cicada-example/demoAction?name=12345&id=10

{
    "code": "9000",
    "dataBody": {
        "index": 1
    },
    "message": "成功"
}

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 void before(Param param) {
        start = System.currentTimeMillis();
    }

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

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

Interceptor Adapter

If you only want to implement one of the methods ,only extends top.crossoverjie.cicada.server.intercept.AbstractCicadaInterceptorAdapter abstract class.

@Interceptor(value = "loggerInterceptor")
public class LoggerInterceptorAbstract extends AbstractCicadaInterceptorAdapter {

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

    @Override
    public void before(Param param) {
        LOGGER.info("logger param=[{}]",param.toString());
    }

}

Performance Test

Image

Test Conditions: 300 concurrency for twice ;1G RAM/one CPU/1Mbps.

Contact author

crossoverJie#gmail.com

Image

About

🚀 Fast lightweight HTTP service framework.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • Java 99.1%
  • Shell 0.9%