Module kong.plugins.system

Kong plugin as system wide plugin, or background worker.

The plugin must be added to the system to be activated, by setting the custom_plugins configuration setting.

Then it should be added as a plugin to some entity (preferably a non-used one, to not cause any runtime overhead) to be able to supply a configuration.

NOTE 1: it will start when Kong starts, or when initially added. When updating or deleting, it requires a Kong reload/restart to effectuate the changes.

NOTE 2: make sure to only add it once! So only one configuration is available. Behaviour is undefined if you add more than one.

NOTE 3: This whole thing is a big hack, until the Plugin API makes it possible to do this in a more structured way.

Info:

  • Copyright: 2017 Kong Inc.
  • License: Apache 2.0

Functions

create_plugin (plugin_name, init_callback, log_prefix) Creates a new plugin to run as a system wide/background process.


Functions

create_plugin (plugin_name, init_callback, log_prefix)
Creates a new plugin to run as a system wide/background process. The callback has signature function(conf) and will at startup run in the init_worker context.

Parameters:

  • plugin_name (string) name of the plugin to create
  • init_callback (function) callback as initializer
  • log_prefix (optional) defaults to "[<plugin_name>] "

Returns:

    the plugin object

Usage:

    -- Example handler.lua file for a background plugin
    local systemwide_plugin = require "kong.plugins.system"
    
    -- Grab pluginname from module name
    local plugin_name = ({...})[1]:match("^kong%.plugins%.([^%.]+)")
    
    local function initialize(conf)
      -- do whatever you want, must be able to run in the init_worker context
    end
    
    -- this is identical to: systemwide_plugin.create_plugin(plugin_name, initialize)
    return systemwide_plugin(plugin_name, initialize)
generated by LDoc 1.4.6 Last updated 2017-11-30 21:55:26