pbrpc

package
v1.1.4-0...-97df346 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2017 License: BSD-2-Clause, BSD-3-Clause, BSL-1.0 Imports: 17 Imported by: 0

README

sofa-pbrpc-go

Go版本sofa-pbrpc的客户端和服务端实现。

安装

$ go get github.com/baidu/sofa-pbrpc/go

依赖

go1.7+

Quick Start

$ go get -u github.com/baidu/sofa-pbrpc/go/examples/echo/echo_server
$ go get -u github.com/baidu/sofa-pbrpc/go/examples/echo/echo_client
$ echo_server &
$ echo_client

生成示例代码

  1. 安装 protoc
  2. 安装protoc插件
$ go get -u github.com/baidu/sofa-pbrpc/go/protoc-gen-go
$ cd $GOPATH/github.com/baidu/sofa-pbrpc/go/examples/echo
$ ./compile_proto.sh

功能说明

  • 对压缩的支持是受限的,目前客户端和服务端可以解析来自于c++的压缩请求或返回,但go没有明确的地方可以主动发起压缩请求

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MagicStr          = [4]byte{'S', 'O', 'F', 'A'}
	ErrBadMagic       = errors.New("bad magic number")
	ErrBadMessageSize = errors.New("message size exceed")
)

Functions

func Invoke

func Invoke(ctx context.Context, method string, args, reply interface{}, cc *ClientConn) error

Invoke sends the RPC request on the wire and returns after response is received. Invoke is called by generated code. Also users can call Invoke directly when it is really needed in their use cases.

Types

type ClientConn

type ClientConn struct {
	// contains filtered or unexported fields
}

ClientConn represents a client connection to an RPC server.

func Dial

func Dial(ctx context.Context, addr string) (*ClientConn, error)

Dial creates a client connection to the given target. The provided Context must be non-nil. If the context expires before the connection is complete, an error is returned. Once successfully connected, any expiration of the context will not affect the connection.

func NewClientConn

func NewClientConn(conn net.Conn) *ClientConn

NewClientConn creates a ClientConn on a given connection

func (*ClientConn) Close

func (c *ClientConn) Close() error

Close tears down the ClientConn and all underlying connections.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is a pbrpc server to serve RPC requests.

func NewServer

func NewServer() *Server

NewServer creates a pbrpc server which has no service registered and has not started to accept requests yet.

func (*Server) RegisterService

func (s *Server) RegisterService(name string, srv interface{})

RegisterService register a service and its implementation to the pbrpc server. Called from the IDL generated code. This must be called before invoking Serve.

func (*Server) Serve

func (s *Server) Serve(l net.Listener) error

Serve accepts incoming connections on the listener l, creating a new ServerConn and service goroutine for each. The service goroutines read pbrpc requests and then call the registered handlers to reply to them. Serve returns when l.Accept fails with errors. TODO Handle non fatal errors

func (*Server) ServeConn

func (s *Server) ServeConn(conn net.Conn)

ServeConn runs the server on a single connection. ServeConn blocks, serving the connection until the client hangs up. The caller typically invokes ServeConn in a go statement.

Directories

Path Synopsis
examples
echo/echo
Package echo is a generated protocol buffer package.
Package echo is a generated protocol buffer package.
protoc-gen-go is a plugin for the Google protocol buffer compiler to generate Go code.
protoc-gen-go is a plugin for the Google protocol buffer compiler to generate Go code.
pbrpc
Package pbrpc outputs sofa-pbrpc service descriptions in Go code.
Package pbrpc outputs sofa-pbrpc service descriptions in Go code.
Package meta is a generated protocol buffer package.
Package meta is a generated protocol buffer package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL