Add *localhost rpc conn in config_defaults and if not specified use *first as strategy

This commit is contained in:
TeoV
2019-12-18 09:44:21 -05:00
parent 0ecec928e4
commit d7f81e8a2f
3 changed files with 14 additions and 13 deletions

View File

@@ -349,7 +349,7 @@ func (cfg *CGRConfig) loadRPCConns(jsnCfg *CgrJsonCfg) (err error) {
if jsnRpcConns, err = jsnCfg.RPCConnJsonCfg(); err != nil {
return
}
// hardoded the *internal and *localhost connections
// hardoded the *internal connection
cfg.rpcConns[utils.MetaInternal] = &RPCConn{
Strategy: rpcclient.PoolFirst,
PoolSize: 0,
@@ -359,18 +359,8 @@ func (cfg *CGRConfig) loadRPCConns(jsnCfg *CgrJsonCfg) (err error) {
},
},
}
cfg.rpcConns[utils.MetaLocalHost] = &RPCConn{
Strategy: rpcclient.PoolFirst,
PoolSize: 0,
Conns: []*RemoteHost{
&RemoteHost{
Address: "127.0.0.1:2012",
Transport: utils.MetaJSON,
},
},
}
for key, val := range jsnRpcConns {
cfg.rpcConns[key] = new(RPCConn)
cfg.rpcConns[key] = NewDfltRPCConn()
if err = cfg.rpcConns[key].loadFromJsonCfg(val); err != nil {
return
}

View File

@@ -53,7 +53,12 @@ const CGRATES_CFG_JSON = `
},
"rpc_conns": {}, // rpc connections definitions
"rpc_conns": {
"*localhost": {
"strategy": "*first",
"conns": [{"address": "127.0.0.1:2012", "transport":"*json"}],
},
}, // rpc connections definitions
"data_db": { // database used to store runtime data (eg: accounts)

View File

@@ -18,6 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package config
import "github.com/cgrates/rpcclient"
// Returns the first cached default value for a RemoteHost connection
func NewDfltRemoteHost() *RemoteHost {
if dfltRemoteHost == nil {
@@ -27,6 +29,10 @@ func NewDfltRemoteHost() *RemoteHost {
return &dfltVal
}
func NewDfltRPCConn() *RPCConn {
return &RPCConn{Strategy: rpcclient.PoolFirst}
}
type RPCConn struct {
Strategy string
PoolSize int