ing
This commit is contained in:
parent
f74046c08a
commit
5b3c02b383
|
@ -2,6 +2,5 @@ package container
|
|||
|
||||
const (
|
||||
CONTAINER_CRAWLERS = "CONTAINER_CRAWLERS"
|
||||
CONTAINER_RPC_WRITE_CHAN = "CONTAINER_RPC_WRITE_CHAN"
|
||||
CONTAINER_RPC_CLIENT_CODEC = "CONTAINER_RPC_CLIENT_CODEC"
|
||||
CONTAINER_RPC_CLIENT = "CONTAINER_RPC_CLIENT"
|
||||
)
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
|
||||
cda "git.loafle.net/commons/di-go/annotation"
|
||||
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
|
||||
_ "git.loafle.net/overflow/commons-go/core/annotation"
|
||||
|
@ -21,16 +21,12 @@ func init() {
|
|||
type ProbeService struct {
|
||||
cda.TypeAnnotation `annotation:"@overflow:RPCService()"`
|
||||
|
||||
RPCWriteChan chan []byte `annotation:"@Resource(name='CONTAINER_RPC_WRITE_CHAN')"`
|
||||
ClientCodec crp.ClientCodec `annotation:"@Resource(name='CONTAINER_RPC_CLIENT_CODEC')"`
|
||||
RPCClient *crc.Client `annotation:"@Resource(name='CONTAINER_RPC_CLIENT')"`
|
||||
}
|
||||
|
||||
func (s *ProbeService) InitService() error {
|
||||
if nil == s.RPCWriteChan {
|
||||
return fmt.Errorf("RPCWriteChan is not valid")
|
||||
}
|
||||
if nil == s.ClientCodec {
|
||||
return fmt.Errorf("ClientCodec is not valid")
|
||||
if nil == s.RPCClient {
|
||||
return fmt.Errorf("RPCClient is not valid")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -50,16 +46,9 @@ func (s *ProbeService) DestroyService() {
|
|||
}
|
||||
|
||||
func (s *ProbeService) Send(method string, params ...interface{}) error {
|
||||
buff, err := s.ClientCodec.NewRequest(method, params, nil)
|
||||
if nil != err {
|
||||
if err := s.RPCClient.Send(method, params...); nil != err {
|
||||
return err
|
||||
}
|
||||
|
||||
select {
|
||||
case s.RPCWriteChan <- buff:
|
||||
default:
|
||||
return fmt.Errorf("Cannot send notification method[%s] params[%v]", method, params)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user