ing
This commit is contained in:
@@ -1,29 +1,36 @@
|
||||
package container
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
logging "git.loafle.net/commons/logging-go"
|
||||
crc "git.loafle.net/commons/rpc-go/client"
|
||||
crpj "git.loafle.net/commons/rpc-go/protocol/json"
|
||||
crr "git.loafle.net/commons/rpc-go/registry"
|
||||
csc "git.loafle.net/commons/server-go/client"
|
||||
cssnc "git.loafle.net/commons/server-go/socket/net/client"
|
||||
ocpcc "git.loafle.net/overflow/commons-go/probe/constants"
|
||||
)
|
||||
|
||||
func newConnector(name string) (*cssnc.Connectors, error) {
|
||||
func newConnector(name string, port int) (*cssnc.Connectors, error) {
|
||||
connector := &cssnc.Connectors{
|
||||
Network: "tcp4",
|
||||
Address: "",
|
||||
Address: fmt.Sprintf("127.0.0.1:%d", port),
|
||||
}
|
||||
connector.ReconnectInterval = 5
|
||||
connector.ReconnectTryTime = 10
|
||||
connector.ReconnectTryTime = 2
|
||||
connector.MaxMessageSize = 4096
|
||||
connector.ReadBufferSize = 4096
|
||||
connector.WriteBufferSize = 4096
|
||||
connector.PongTimeout = 60
|
||||
connector.PingTimeout = 10
|
||||
connector.PingPeriod = 9
|
||||
|
||||
connector.Name = name
|
||||
|
||||
connector.OnDisconnected = func(connector csc.Connector) {
|
||||
logging.Logger().Debugf("Client[%s] has been disconnected", connector.GetName())
|
||||
}
|
||||
|
||||
return connector, nil
|
||||
}
|
||||
|
||||
@@ -43,3 +50,12 @@ func newClient(name string, connector csc.Connector, services []interface{}) *cr
|
||||
Name: name,
|
||||
}
|
||||
}
|
||||
|
||||
func NewClient(containerType ocpcc.ContainerType, port int, services []interface{}) (*crc.Client, error) {
|
||||
connector, err := newConnector(containerType.String(), port)
|
||||
if nil != err {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return newClient(containerType.String(), connector, services), nil
|
||||
}
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
package container
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
crc "git.loafle.net/commons/rpc-go/client"
|
||||
"git.loafle.net/overflow/probe/config"
|
||||
)
|
||||
|
||||
func NewDiscovery(services ...interface{}) (*crc.Client, error) {
|
||||
config := config.GetConfig()
|
||||
if nil == config {
|
||||
return nil, fmt.Errorf("Config is not available")
|
||||
}
|
||||
|
||||
connector, err := newConnector("Probe")
|
||||
if nil != err {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return newClient("Probe", connector, services), nil
|
||||
}
|
||||
Reference in New Issue
Block a user