container_discovery/client/client.go

52 lines
1.5 KiB
Go
Raw Permalink Normal View History

2018-05-03 06:30:23 +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"
2018-07-02 15:19:56 +00:00
crcodec "git.loafle.net/commons/rpc-go/codec"
2018-05-03 06:30:23 +00:00
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_discovery/crawler"
"git.loafle.net/overflow/container_discovery/service"
)
func New(portNumber int) *crc.Client {
2018-05-03 08:40:02 +00:00
connector, err := occ.NewConnector(occp.ContainerDiscovery, portNumber)
if nil != err {
logging.Logger().Panic(err)
}
2018-07-02 15:19:56 +00:00
rpcClientCodec := crpj.NewCustomClientCodec(crcodec.NewCompressionCodecSelector(connector.GetCompressionThreshold()))
2018-05-03 08:40:02 +00:00
ch := &ClientHandlers{}
ch.Name = occp.ContainerDiscovery.String()
ch.Connector = connector
ch.RPCCodec = rpcClientCodec
c := &crc.Client{
ClientHandler: ch,
}
2018-05-03 06:30:23 +00:00
cdr.RegisterResource(container.CONTAINER_CRAWLERS, crawler.GetCrawlers())
2018-05-03 08:40:02 +00:00
cdr.RegisterResource(container.CONTAINER_RPC_CLIENT, c)
2018-05-03 06:30:23 +00:00
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
2018-05-03 08:40:02 +00:00
return c
2018-05-03 06:30:23 +00:00
}