container_network/client/client.go

51 lines
1.4 KiB
Go
Raw Normal View History

2018-05-03 09:54:38 +00:00
package client
import (
cdr "git.loafle.net/commons/di-go/registry"
"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"
occp "git.loafle.net/overflow/commons-go/config/probe"
occa "git.loafle.net/overflow/commons-go/core/annotation"
"git.loafle.net/overflow/container-go"
occ "git.loafle.net/overflow/container-go/client"
"git.loafle.net/overflow/container_network/crawler"
"git.loafle.net/overflow/container_network/service"
)
func New(portNumber int) *crc.Client {
rpcClientCodec := crpj.NewClientCodec()
2018-05-03 10:36:27 +00:00
connector, err := occ.NewConnector(occp.ContainerNetwork, portNumber)
2018-05-03 09:54:38 +00:00
if nil != err {
logging.Logger().Panic(err)
}
ch := &ClientHandlers{}
ch.Name = occp.ContainerNetwork.String()
ch.Connector = connector
ch.RPCCodec = rpcClientCodec
c := &crc.Client{
ClientHandler: ch,
}
cdr.RegisterResource(container.CONTAINER_CRAWLERS, crawler.GetCrawlers())
cdr.RegisterResource(container.CONTAINER_RPC_CLIENT, c)
services, err := cdr.GetInstancesByAnnotationType(occa.RPCServiceAnnotationType)
if nil != err {
logging.Logger().Panic(err)
}
rpcRegistry := crr.NewRPCRegistry()
rpcRegistry.RegisterServices(services...)
ch.RPCInvoker = rpcRegistry
ch.Services = services
ch.OrderedServices = service.OrderedServices
return c
}