This commit is contained in:
crusader 2018-05-03 17:35:13 +09:00
parent f74046c08a
commit 5b3c02b383
2 changed files with 7 additions and 19 deletions

View File

@ -1,7 +1,6 @@
package container package container
const ( const (
CONTAINER_CRAWLERS = "CONTAINER_CRAWLERS" CONTAINER_CRAWLERS = "CONTAINER_CRAWLERS"
CONTAINER_RPC_WRITE_CHAN = "CONTAINER_RPC_WRITE_CHAN" CONTAINER_RPC_CLIENT = "CONTAINER_RPC_CLIENT"
CONTAINER_RPC_CLIENT_CODEC = "CONTAINER_RPC_CLIENT_CODEC"
) )

View File

@ -6,7 +6,7 @@ import (
cda "git.loafle.net/commons/di-go/annotation" cda "git.loafle.net/commons/di-go/annotation"
cdr "git.loafle.net/commons/di-go/registry" cdr "git.loafle.net/commons/di-go/registry"
crp "git.loafle.net/commons/rpc-go/protocol" crc "git.loafle.net/commons/rpc-go/client"
// For annotation // For annotation
_ "git.loafle.net/overflow/commons-go/core/annotation" _ "git.loafle.net/overflow/commons-go/core/annotation"
@ -21,16 +21,12 @@ func init() {
type ProbeService struct { type ProbeService struct {
cda.TypeAnnotation `annotation:"@overflow:RPCService()"` cda.TypeAnnotation `annotation:"@overflow:RPCService()"`
RPCWriteChan chan []byte `annotation:"@Resource(name='CONTAINER_RPC_WRITE_CHAN')"` RPCClient *crc.Client `annotation:"@Resource(name='CONTAINER_RPC_CLIENT')"`
ClientCodec crp.ClientCodec `annotation:"@Resource(name='CONTAINER_RPC_CLIENT_CODEC')"`
} }
func (s *ProbeService) InitService() error { func (s *ProbeService) InitService() error {
if nil == s.RPCWriteChan { if nil == s.RPCClient {
return fmt.Errorf("RPCWriteChan is not valid") return fmt.Errorf("RPCClient is not valid")
}
if nil == s.ClientCodec {
return fmt.Errorf("ClientCodec is not valid")
} }
return nil return nil
@ -50,16 +46,9 @@ func (s *ProbeService) DestroyService() {
} }
func (s *ProbeService) Send(method string, params ...interface{}) error { func (s *ProbeService) Send(method string, params ...interface{}) error {
buff, err := s.ClientCodec.NewRequest(method, params, nil) if err := s.RPCClient.Send(method, params...); nil != err {
if nil != err {
return err return err
} }
select {
case s.RPCWriteChan <- buff:
default:
return fmt.Errorf("Cannot send notification method[%s] params[%v]", method, params)
}
return nil return nil
} }