Coder Social home page Coder Social logo

fiber-net-gateway

中文版

A low-code API gateway | FaaS framework based on a script engine. The function implemented is to execute a script for responding HTTP requests.

In the script, you can write some calls to http, dubbo services and other simple logic, which can implement protocol conversion, reverse proxy, service orchestration, BFF and other functions.

The project comprises three fundamental components:

  • Netty-based asynchronous HTTP server.
  • Netty-based asynchronous HTTP client, supporting https, DNS and connection pooling.
  • Scripting engines with both interpreter and AOT (Ahead of Time Compilation).

The performance is very high, and it is the fastest java gateway | FaaS framework in the world (without any other one), It is 1.5 times faster than nginx-luajit and 4.4 times faster than spring-mvc (Performance Test). There are some highlights as follows:

  • A scripting language designed specifically for scenarios such as FaaS | API gateway, which is different from other complex and difficult-to-understand configurations for gateways and is simple and easy to understand.
  • All components are asynchronous, no thread pool is used, and there are no other threads except for Netty's IO threads.

There are two ways to execute scripts, and both support Coroutine (Principle Description):

  • Interpreter mode: Compile the script into a series of assembly-like instructions, and simulate the execution of the instructions in Java, similar to a Lua interpreter;
  • AOT (Ahead of Time Compilation) mode: The script will be compiled into a java class, which will be run directly by the JVM. Like rust, it supports coroutines through state machine compilation.

PS: It is only a framework. If it is used in a production environment, secondary development is required, such as accessing the configuration center and extending script functions.

Synopsis

  • Compilation
git clone https://github.com/fiber-net-gateway/fiber-net-gateway.git
cd fiber-net-gateway
mvn clean package -DskipTests
cd fiber-gateway-example/target
  • Create a script file, the script content is to sum up the array
mkdir scripts
cat > scripts/fiber-net.js << EOF
let bodyArray = req.readJson();
let sum = 0;
for (let _, value of bodyArray) {
    sum = sum + value;
}
return "sum = " + sum;
EOF
  • Running
java -jar fiber-gateway-example-1.0-SNAPSHOT.jar scripts
  • Test: The script above will be executed once for each request
# Call the service to sum the array
curl 127.0.0.1:16688 -XPOST -H'Content-Type: application/json' -d'[1,2,3,4]' -i
# ======================================================
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
date: Fri, 10 May 2024 08:28:01 GMT
server: fiber-net(fn)/dev/dev
transfer-encoding: chunked

"sum = 10"

For detailed instructions, please refer to the User Manual

For extended secondary development, please refer to Development Document

PLUGINS

there are some plugins for fiber-gateway. Official Plugins

fiber-net-gateway's Projects

fiber-net-gateway icon fiber-net-gateway

A low code API gateway | FaaS framework based on script engine. The implemented function is to execute a script for each HTTP request received. Used for protocol conversion, reverse proxy, service orchestration, BFF, etc. 基于脚本引擎的低代码 API 网关 |FaaS 框架,用于 FaaS BFF,服务编排等。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.