4 Star 4 Fork 1

SyncGithub / apisix

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
wasm.md 4.43 KB
一键复制 编辑 原始数据 按行查看 历史
罗泽轩 提交于 2021-10-22 16:29 . feat: initial wasm support (#5288)
title
WASM

APISIX supports WASM plugins written with Proxy WASM SDK.

This plugin requires APISIX to run on APISIX-OpenResty, and is under construction. Currently, only a few APIs are implemented. Please follow wasm-nginx-module to know the progress.

Programming model

The plugin supports the follwing concepts from Proxy WASM:

                    Wasm Virtual Machine
┌────────────────────────────────────────────────────────────────┐
│      Your Plugin                                               │
│          │                                                     │
│          │ 1: 1                                                │
│          │         1: N                                        │
│      VMContext  ──────────  PluginContext                      │
│                                           ╲ 1: N               │
│                                            ╲                   │
│                                             ╲  HttpContext     │
│                                               (Http stream)    │
└────────────────────────────────────────────────────────────────┘
  • All plugins run in the same WASM VM, like the Lua plugin in the Lua VM
  • Each plugin has its own VMContext (the root ctx)
  • Each configured route/global rules has its own PluginContext (the plugin ctx). For example, if we have a service configuring with WASM plugin, and two routes inherit from it, there will be two plugin ctxs.
  • Each HTTP request which hits the configuration will have its own HttpContext (the HTTP ctx). For example, if we configure both global rules and route, the HTTP request will have two HTTP ctxs, one for the plugin ctx from global rules and the other for the plugin ctx from route.

How to use

First of all, we need to define the plugin in config.yaml:

wasm:
  plugins:
    - name: wasm_log # the name of the plugin
      priority: 7999 # priority
      file: t/wasm/log/main.go.wasm # the path of `.wasm` file

That's all. Now you can use the wasm plugin as a regular plugin.

For example, enable this plugin on the specified route:

curl -i http://127.0.0.1:9080/apisix/admin/routes/1  -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
    "uri": "/index.html",
    "plugins": {
         "wasm_log": {
             "conf": "blahblah"
         }
    },
    "upstream": {
        "type": "roundrobin",
        "nodes": {
            "127.0.0.1:1980": 1
        }
    }
}'

Attributes below can be configured in the plugin:

Name Type Requirement Default Valid Description
conf string required the plugin ctx configuration which can be fetched via Proxy WASM SDK
Java
1
https://gitee.com/sync-github/apisix.git
git@gitee.com:sync-github/apisix.git
sync-github
apisix
apisix
master

搜索帮助