Sunday, October 2, 2022
HomeJavaWriting your personal service discovery consumer for Apache APISIX

Writing your personal service discovery consumer for Apache APISIX


native util = require("apisix.cli.util")                                   (1)
native yaml = require("tinyyaml")                                          (2)

native operate read_file()
    native content material, err = util.read_file("/var/apisix/nodes.yaml")         (3)
    if not content material then
        return
    finish
    native nodes_conf, err = yaml.parse(content material)                           (4)
    if not nodes_conf then
        return
    finish
    if not nodes then
        nodes = {}
    finish
    for uri, weight in pairs(nodes_conf.nodes) do                         (5)
        native host_port = {}
        for str in string.gmatch(uri, "[^:]+") do
            desk.insert(host_port, str)                                  (6)
        finish
        native node = {
          host = host_port[1],
          port = tonumber(host_port[2]),
          weight = weight,
        }                                                                 (7)
        desk.insert(nodes, node)                                         (8)
    finish
finish

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments