DispatcherHost.GetRPCConnection

This commit is contained in:
DanB
2019-03-28 15:33:28 +01:00
parent a9d913231a
commit 8b2b5dece0
2 changed files with 32 additions and 7 deletions

View File

@@ -21,8 +21,11 @@ package engine
import (
"math/rand"
"sort"
"time"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/utils"
"github.com/cgrates/rpcclient"
)
type DispatcherConn struct {
@@ -123,17 +126,39 @@ func (dps DispatcherProfiles) Sort() {
sort.Slice(dps, func(i, j int) bool { return dps[i].Weight > dps[j].Weight })
}
<<<<<<< HEAD
type DispatcherHostConn struct {
Address string
Transport string
TLS bool
}
=======
// DispatcherHost represents one virtual host with po
>>>>>>> DispatcherHost.GetRPCConnection
type DispatcherHost struct {
Tenant string
ID string
Conns []*DispatcherHostConn
Tenant string
ID string
Conns []*config.HaPoolConfig
rpcConn rpcclient.RpcClientConnection
}
func (dP *DispatcherHost) TenantID() string {
return utils.ConcatenatedKey(dP.Tenant, dP.ID)
func (dH *DispatcherHost) TenantID() string {
return utils.ConcatenatedKey(dH.Tenant, dH.ID)
}
// GetRPCConnection builds or returns the cached connection
func (dH *DispatcherHost) GetRPCConnection() (rpcConn rpcclient.RpcClientConnection, err error) {
if dH.rpcConn == nil {
cfg := config.CgrConfig()
if dH.rpcConn, err = NewRPCPool(
rpcclient.POOL_FIRST,
cfg.TlsCfg().ClientKey,
cfg.TlsCfg().ClientCerificate, cfg.TlsCfg().CaCertificate,
cfg.GeneralCfg().ConnectAttempts, cfg.GeneralCfg().Reconnects,
cfg.GeneralCfg().ConnectTimeout, cfg.GeneralCfg().ReplyTimeout,
dH.Conns, nil, time.Duration(0), false); err != nil {
return
}
}
return dH.rpcConn, nil
}

View File

@@ -2661,10 +2661,10 @@ func APItoDispatcherHost(tpDPH *utils.TPDispatcherHost) (dpp *DispatcherHost) {
dpp = &DispatcherHost{
Tenant: tpDPH.Tenant,
ID: tpDPH.ID,
Conns: make([]*DispatcherHostConn, len(tpDPH.Conns)),
Conns: make([]*config.HaPoolConfig, len(tpDPH.Conns)),
}
for i, conn := range tpDPH.Conns {
dpp.Conns[i] = &DispatcherHostConn{
dpp.Conns[i] = &config.HaPoolConfig{
Address: conn.Address,
Transport: conn.Transport,
TLS: conn.TLS,