kong:

根据Nginx的不同执行阶段,kong先执行初始化master和worker进程。

init_by_lua_block {
require 'resty.core'
kong = require 'kong'
kong.init()
}

安装完之后加载/usr/local/share/lua/5.1/下面的kong.lua,调用init()方法,加载配置文件,创建事件,建立路由。

  singletons.dns = dns(config)
singletons.loaded_plugins = assert(load_plugins(config, dao, events))
singletons.serf = Serf.new(config, dao)
singletons.dao = dao
singletons.events = events
singletons.configuration = config

在数据库中检查所有的可用的插件,然后加载插件,插件必须有两个文件handler.lua和schema.lua。以keyauth插件为例,格式为:kong.plugins.keyauth.handler和kong.plugins.keyauth.schema。

如果存在kong.plugins.keyauth.hooks则注册相应的事件。

不同的插件有不同的优先级,根据插件PRIORITY大小排序。


init_worker_by_lua_block {
kong.init_worker()
}

初始化worker_events(这里我不懂,根据worker的pid,建立路由和注册事件)

kong入口server监听8000端口,还开放一个8001端口提供了restful接口,用于后台查询api的调用,插件等。

处理中间任务,然后init_worker(),调用后台任务:

local function keepalive_handler(premature)
if premature then
return
end -- all workers need to register a recurring timer, in case one of them
-- crashes. Hence, this must be called before the `get_lock()` call.
create_timer(KEEPALIVE_INTERVAL, keepalive_handler) if not get_lock(KEEPALIVE_KEY, KEEPALIVE_INTERVAL) then
return
end log(DEBUG, "sending keepalive event to datastore") local nodes, err = singletons.dao.nodes:find_all {
name = singletons.serf.node_name
}
if err then
log(ERR, "could not retrieve nodes from datastore: ", err) elseif #nodes == 1 then
local node = nodes[1]
local _, err = singletons.dao.nodes:update(node, node, {
ttl = singletons.configuration.cluster_ttl_on_failure,
quiet = true
})
if err then
log(ERR, "could not update node in datastore:", err)
end
end
end

在8000端口中:

access_by_lua_block {
kong.access()
}

before()方法相当于api的一个middleware,检测路由和http方法,获取ip端口,域名等。

after()方法返回一些kong的执行时间等。

在access中加载kong.plugins.keyauth.handler.lua的方法中的access方法,调用前后分别调用before()和after()方法。

  for plugin, plugin_conf in plugins_iterator(singletons.loaded_plugins, true) do
plugin.handler:access(plugin_conf)
end

遍历插件列表,存储在ngx.ctx.plugins_for_request中

header_filter_by_lua_block {
kong.header_filter()
} body_filter_by_lua_block {
kong.body_filter()
} log_by_lua_block {
kong.log()
}

kong流程学习的更多相关文章

  1. rpm构建流程学习总结

    rpm构建流程 学习链接: b站马哥: https://www.bilibili.com/video/BV1ai4y1N7gp RedHat: https://access.redhat.com/do ...

  2. web 安全之页面解析的流程学习

    0x00 任务内容: 理解域名解析的整个过程 理解 web 页面请求的整个流程,绘制流程图(nginx 处理的 11 个过程) 学习 http 协议中的字段及含义 学习 http 请求方法以及返回状态 ...

  3. VerilogHDL概述与数字IC设计流程学习笔记

    一.HDL的概念和特征 HDL,Hard Discrimination Language的缩写,翻译过来就是硬件描述语言.那么什么是硬件描述语言呢?为什么不叫硬件设计语言呢?硬件描述语言,顾名思义就是 ...

  4. MySQL Backup mysqldump备份流程学习

    我们都知道MySQL逻辑备份工具mysqldump可以保证备份数据的一致性,但是它是怎么保持一致性的? 本文不讨论mysqldump具体的选项和用法,一直对mysqldump的工作机制梳理的不太清楚, ...

  5. 挖坑:handoop2.6 开启kerberos(全流程学习记录)

    目录: 1.涉及插件简介 2.安装步骤 3.日志错误查看 1.kerberos是什么东西 度娘指导: Kerberos 是一种网络认证协议,其设计目标是通过密钥系统为 客户机 / 服务器 应用程序提供 ...

  6. tf中计算图 执行流程学习【转载】

    转自:https://blog.csdn.net/dcrmg/article/details/79028003 https://blog.csdn.net/qian99/article/details ...

  7. Centos的启动流程学习

    Centos 6 的启动流程: POST ---> Boot sequence(BOIS) ---> Boot loader (MBR) --->  kernel(ramdiskfs ...

  8. FFmpeg处理音视频流程学习笔记

    原文作者:一叶知秋0830 链接:https://www.jianshu.com/p/1b715966af50 FFmpeg处理音视频完整流程包括5个阶段(输入文件—>编码数据包—>解码后 ...

  9. Mybatis执行流程学习之手写mybatis雏形

    Mybatis是目前开发中最常用的一款基于ORM思想的半自动持久层框架,平时我们都仅仅停留在使用阶段,对mybatis是怎样运行的并不清楚,今天抽空找到一些资料自学了一波,自己写了一个mybatis的 ...

随机推荐

  1. 小红帽安装centos的yum的一些坑!

    [root@localhost ~]# lsanaconda-ks.cfg yum-3.4.3-158.el7.centos.noarch.rpm yum-updateonboot-1.1.31-45 ...

  2. hp raid json

    hp机器均已在装OS之前划好raid,统一规格为2*480G SSD, 12*4T SATA ,2*1.6T SSD,其中2*480G SSD做系统盘,划分raid1 已知disk controlle ...

  3. 替换Fragment 报错 The specified child already has a parent. You must call removeView() on the child's parent first.

    在将一个fragment替换到一个frameLayout的时候报错: code: transaction.replace(R.id.fragment_container, fragment2); 错误 ...

  4. CentOS 6.3下安装Vsftp,虚拟用户

    CentOS 6.3下安装Vsftp,虚拟用户一.安装:1.安装Vsftpd服务相关部件:[root@linuxidc.com ~]# yum install vsftpd*Dependencies ...

  5. 最小生成树 $Kruskal$ 算法

    #include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 10; int h[maxn], v[maxn], ...

  6. Struts1 多个配置文件的实现

    在Struts 1.0中,我们只能在web.xml中为ActionServlet指定一个配置文件,这对于我们这些网上的教学例子来说当然没什么问题,但是在实际的应用开发过程中,可能会有些麻烦.因为许多开 ...

  7. P2215 [HAOI2007]上升序列

    题目描述 对于一个给定的S={a1,a2,a3,…,an},若有P={ax1,ax2,ax3,…,axm},满足(x1<x2<…<xm) 且(ax1<ax2<…<a ...

  8. 2017 多校4 Matching In Multiplication(二分图)

    Matching In Multiplication 题解: 首先如果一个点的度数为1,那么它的匹配方案是固定的,继而我们可以去掉这一对点.通过拓扑我们可以不断去掉所有度数为1的点. 那么剩下的图中左 ...

  9. 《c程序设计语言》读书笔记-3-3-速记扩充

    #include <io.h> #include <stdio.h> #include <string.h> #include <stdlib.h> i ...

  10. HDU 5366 dp 递推

    The mook jong Accepts: 506 Submissions: 1281 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...