Lua connection pool for tarantool net.box with network zones support.
pool:init(cfg)
- init connection pool with given configpool:one(zone_id)
- returns random active connection from given zone(can be nil)pool:all(zone_id)
- returns all active connections from given zone(can be nil)pool:zone_list()
- returns list of network zones idspool:get_heartbeat()
- returns monitoring state
if zone_id
is nil - return connections from all zones
on_connected
- all nodes connectedon_connected_one
- one node connectedon_disconnect
- lost all connations in poolon_disconnect_one
- one node disconnecton_disconnect_zone
- all nodes in zone disconnectedon_connfail
- monitoring detected connection problemon_init
- init complete, monitoring fibers started
global:
pool_name
- connection pool idmonitor
- enable connection monitoring(by defaulttrue
)servers
- table with servers settings
servers:
uri
- server uri with portlogin
password
zone
- network zone(can be nil)
p = require('connpool')
-- create new pool
pool = p.new()
-- set callback
pool.on_connected = function(self)
log.info('hello world')
end
-- config with 2 nodes in 2 zones and monitoring
local cfg = {
pool_name = 'mypool';
servers = {
{
uri = 'localhost:3313', login = 'tester',
password = 'pass', zone = 'myzone1'
};
{
uri = 'localhost:3314', login = 'tester',
password = 'pass', zone = 'myzone2'
};
};
monitor = true;
}
-- start
pool:init(cfg)
if there is no zone specified - all servers are in single zone