This commit is contained in:
crusader
2018-04-18 23:56:13 +09:00
parent 92d7926d3f
commit d2d34699aa
25 changed files with 606 additions and 271 deletions

View File

@@ -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
}

View File

@@ -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
}