diff --git a/constants.go b/constants.go index b62b525..1facbab 100644 --- a/constants.go +++ b/constants.go @@ -1,5 +1,7 @@ package container const ( - CONTAINER_CRAWLERS = "CONTAINER_CRAWLERS" + CONTAINER_CRAWLERS = "CONTAINER_CRAWLERS" + CONTAINER_RPC_CLIENT_CODEC = "CONTAINER_RPC_CLIENT_CODEC" + CONTAINER_RPC_WRITE_CHAN = "CONTAINER_RPC_WRITE_CHAN" ) diff --git a/service/ProbeService.go b/service/ProbeService.go index 0d353f9..7d4d110 100644 --- a/service/ProbeService.go +++ b/service/ProbeService.go @@ -5,6 +5,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" // For annotation _ "git.loafle.net/overflow/commons-go/core/annotation" @@ -18,6 +19,9 @@ func init() { type ProbeService struct { cda.TypeAnnotation `annotation:"@overflow:RPCService()"` + + RPCClientCodec crp.ClientCodec `annotation:"@Resource(name='CONTAINER_RPC_CLIENT_CODEC')"` + RPCWriteChan chan<- []byte `annotation:"@Resource(name='CONTAINER_RPC_WRITE_CHAN')"` } func (s *ProbeService) InitService() error { @@ -38,6 +42,12 @@ func (s *ProbeService) DestroyService() { } func (s *ProbeService) Send(method string, params ...interface{}) error { + buf, err := s.RPCClientCodec.NewRequest(method, params, nil) + if nil != err { + return err + } + + s.RPCWriteChan <- buf return nil } diff --git a/servlet/rpc-servlet.go b/servlet/rpc-servlet.go index c216b28..145d12f 100644 --- a/servlet/rpc-servlet.go +++ b/servlet/rpc-servlet.go @@ -19,7 +19,8 @@ type RPCServlet interface { type RPCServlets struct { cssn.Servlets - RPCInvoker crr.RPCInvoker + RPCInvoker crr.RPCInvoker + RPCWriteChan <-chan []byte } func (s *RPCServlets) Handshake(servletCtx server.ServletCtx, conn net.Conn) error { @@ -72,6 +73,8 @@ func (s *RPCServlets) Handle(servletCtx server.ServletCtx, } writeChan <- replyBuff + case buf := <-s.RPCWriteChan: + writeChan <- buf case <-stopChan: return }