baidurpc

package module
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2022 License: Apache-2.0 Imports: 29 Imported by: 2

README

baidurpc

baidurpc是一种基于TCP协议的二进制高性能RPC通信协议实现。它以Protobuf作为基本的数据交换格式。 本版本基于golang实现.完全兼容jprotobuf-rpc-socket: https://github.com/Baidu-ecom/Jprotobuf-rpc-socket

Go Report Card Go codecov Releases Go Reference LICENSE

features:

  • 内置连接池,具备更高的性能,低延迟 QPS: 5w+
  • 支持自动重连功能[Done]
  • 支持附件发送[Done]
  • 支持超时功能[Done]
  • 压缩功能,支持GZip与Snappy[Done]
  • 集成内置HTTP管理功能[TODO]
  • Client支持Ha的负载均衡功能[Done]
  • 灵活的超时设置功能[Done] 基于timewheel实现
  • 分包chunk支持,针对大数据包支持拆分包的发送的功能[Done]
  • 支持Web管理能力以及内置能力[Done] 查看
  • 支持同步发布为Http JSON协议[Done] [>= v1.2.0] ​

Installing

To start using pbrpc, install Go and run go get:

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

Which version

version protobuf package
<= 1.2.x github.com/golang/protobuf
1.3.x google.golang.org/protobuf

FYI: 由于这两个pb类库并不是完全兼容,官方推荐使用 google.golang.org/protobuf

使用说明与Demo

Quick Start(服务发布)
Quick Start(客户端调用)
同步发布http rpc服务
更多特性使用说明
Demo开发示例代码

License

brpc is Apache 2.0 licensed.

Documentation

Overview

Go support for Protocol Buffers RPC which compatiable with https://github.com/Baidu-ecom/Jprotobuf-rpc-socket

Copyright 2002-2007 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Go support for Protocol Buffers RPC which compatiable with https://github.com/Baidu-ecom/Jprotobuf-rpc-socket

Copyright 2002-2007 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Go support for Protocol Buffers RPC which compatiable with https://github.com/Baidu-ecom/Jprotobuf-rpc-socket

Copyright 2002-2007 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Go support for Protocol Buffers RPC which compatiable with https://github.com/Baidu-ecom/Jprotobuf-rpc-socket

Copyright 2002-2007 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Go support for Protocol Buffers RPC which compatiable with https://github.com/Baidu-ecom/Jprotobuf-rpc-socket

Copyright 2002-2007 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

  • @Author: Malin Xie
  • @Description:
  • @Date: 2021-04-26 18:18:59

Go support for Protocol Buffers RPC which compatiable with https://github.com/Baidu-ecom/Jprotobuf-rpc-socket

Copyright 2002-2007 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Go support for Protocol Buffers RPC which compatiable with https://github.com/Baidu-ecom/Jprotobuf-rpc-socket

Copyright 2002-2007 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

  • @Author: Malin Xie
  • @Description:
  • @Date: 2021-08-19 13:22:01

Go support for Protocol Buffers RPC which compatiable with https://github.com/Baidu-ecom/Jprotobuf-rpc-socket

Copyright 2002-2007 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Go support for Protocol Buffers RPC which compatiable with https://github.com/Baidu-ecom/Jprotobuf-rpc-socket

Copyright 2002-2007 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Go support for Protocol Buffers RPC which compatiable with https://github.com/Baidu-ecom/Jprotobuf-rpc-socket

Copyright 2002-2007 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Go support for Protocol Buffers RPC which compatiable with https://github.com/Baidu-ecom/Jprotobuf-rpc-socket

Copyright 2002-2007 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

  • @Author: Malin Xie
  • @Description:
  • @Date: 2021-07-26 17:09:25

Go support for Protocol Buffers RPC which compatiable with https://github.com/Baidu-ecom/Jprotobuf-rpc-socket

Copyright 2002-2007 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	SIZE = 12

	MagicSize = 4

	MAGIC_CODE = "PRPC"

	COMPRESS_NO     int32 = 0
	COMPRESS_SNAPPY int32 = 1
	COMPRESS_GZIP   int32 = 2
)
View Source
const (
	HttpRpcPath = "/rpc/"

	LogId_key        = "X-LogID"
	Auth_key         = "X-Authenticate"
	Trace_Id_key     = "X-Trace_ID"
	Trace_Span_key   = "X-Trace_Span"
	Trace_Parent_key = "X-Trace_Parent"
	Request_Meta_Key = "X-Request-Meta" // Json value
)
View Source
const (
	/** success status. */
	ST_SUCCESS int = 0

	/** 方法未找到异常. */
	ST_SERVICE_NOTFOUND int = 1001

	/** 未知异常. */
	ST_ERROR int = 2001

	/** 验证错误. */
	ST_AUTH_ERROR = 1004

	//  log id key
	KT_LOGID = "_logid_"

	RPC_STATUS_SERVICENAME = "___baidurpc_service"

	// in seconds
	Reqeust_QPS_Expire = 300 //

	Proto2_Version = "proto2"

	Shutdown_Timeout = time.Second
)
View Source
const REQUIRED_TYPE = "baidurpc.RpcDataPackage"
View Source
const (
	ST_READ_TIMEOUT = 62
)

Variables

View Source
var (
	LOG_SERVER_REPONSE_ERROR  = "[client-002]Server response error. code=%d, msg='%s'"
	LOG_CLIENT_TIMECOUST_INFO = "[client-101]Server name '%s' method '%s' process cost '%.5g' seconds"
)
View Source
var (
	Empty_Head = make([]byte, SIZE)

	HB_SERVICE_NAME = "__heartbeat"
	HB_METHOD_NAME  = "__beat"
)
View Source
var (
	LOG_SERVICE_NOTFOUND    = "[server-" + strconv.Itoa(ST_SERVICE_NOTFOUND) + "]Service name '%s' or method name '%s' not found"
	LOG_SERVICE_DUPLICATE   = "[server-004]Service name '%s' or method name '%s' already exist"
	LOG_SERVER_STARTED_INFO = "[server-100]BaiduRpc server started on '%v'"
	LOG_INTERNAL_ERROR      = "[server-" + strconv.Itoa(ST_ERROR) + "] unknown internal error:'%s'"
	LOG_TIMECOST_INFO       = "[server-101]Server name '%s' method '%s' process cost '%.5g' seconds"
	LOG_TIMECOST_INFO2      = "[server-102]Server name '%s' method '%s' process cost '%.5g' seconds.(without net cost) "

	DEAFULT_IDLE_TIME_OUT_SECONDS = 10

	MessageType = reflect.TypeOf(m)
)

error log info definition

View Source
var File_brpc_meta_proto protoreflect.FileDescriptor
View Source
var (
	LOG_CLOSE_CONNECT_INFO = "[codec-100]Do close connection. connection info:%v"
)
View Source
var (
	LOG_INVALID_BYTES = "[marshal-004]Invalid byte array. maybe a broken byte stream. Received '%b'"
)

error log info definition

View Source
var (
	LOG_INVALID_PORT = "[conn-003]invalid parameter 'url' of port property is '%d'"
)
View Source
var NANO_IN_SECONDS = 1000000000.0

Functions

func Attachement

func Attachement(context context.Context) []byte

Attachment utility function to get attachemnt from context

func BindAttachement

func BindAttachement(c context.Context, attachement interface{}) context.Context

BindAttachement add attachement value to the context

func BindError

func BindError(c context.Context, err error) context.Context

BindError add error value to the context

func BindLogId added in v1.1.3

func BindLogId(c context.Context, logid int64) context.Context

BindError add error value to the context

func CloseBatchConnection

func CloseBatchConnection(connections []Connection)

CloseBatchConnection close batch connections

func Error

func Error(args ...interface{})

Error logs to the ERROR, WARNING, and INFO logs. Arguments are handled in the manner of fmt.Print; a newline is appended if missing.

func Errorf

func Errorf(format string, args ...interface{})

Errorf logs to the ERROR, WARNING, and INFO logs. Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.

func Errors

func Errors(c context.Context) error

BindError add error value to the context

func GUNZIP

func GUNZIP(b []byte) ([]byte, error)

GUNZIP do unzip action by gzip package

func GZIP

func GZIP(b []byte) ([]byte, error)

GZIP do gzip action by gzip package

func GetServiceId

func GetServiceId(serviceName, methodName string) string

func Info

func Info(args ...interface{})

Info logs to the INFO log. Arguments are handled in the manner of fmt.Print; a newline is appended if missing.

func Infof

func Infof(format string, args ...interface{})

Infof logs to the INFO log. Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.

func LogID added in v1.1.3

func LogID(context context.Context) int64

func TimetookInSeconds

func TimetookInSeconds(currentNano int64) float64

get time took in seconds

func UnescapeUnicode added in v1.1.3

func UnescapeUnicode(raw []byte) ([]byte, error)

UnescapeUnicode

func Warning

func Warning(args ...interface{})

Warning logs to the WARNING and INFO logs. Arguments are handled in the manner of fmt.Print; a newline is appended if missing.

func Warningf

func Warningf(format string, args ...interface{})

Warningf logs to the WARNING and INFO logs. Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.

Types

type AuthService added in v1.1.1

type AuthService interface {
	// Authenticate do auth action if return true auth success
	Authenticate(service, name string, authToken []byte) bool
}

AuthService authenticate service

type ChunkInfo

type ChunkInfo struct {
	StreamId int64 `protobuf:"varint,1,opt,name=stream_id,json=streamId,proto3" json:"stream_id,omitempty"`
	ChunkId  int64 `protobuf:"varint,2,opt,name=chunk_id,json=chunkId,proto3" json:"chunk_id,omitempty"`
	// contains filtered or unexported fields
}

func (*ChunkInfo) Descriptor deprecated

func (*ChunkInfo) Descriptor() ([]byte, []int)

Deprecated: Use ChunkInfo.ProtoReflect.Descriptor instead.

func (*ChunkInfo) GetChunkId

func (x *ChunkInfo) GetChunkId() int64

func (*ChunkInfo) GetStreamId

func (x *ChunkInfo) GetStreamId() int64

func (*ChunkInfo) ProtoMessage

func (*ChunkInfo) ProtoMessage()

func (*ChunkInfo) ProtoReflect added in v1.3.0

func (x *ChunkInfo) ProtoReflect() protoreflect.Message

func (*ChunkInfo) Reset

func (x *ChunkInfo) Reset()

func (*ChunkInfo) String

func (x *ChunkInfo) String() string

type Connection

type Connection interface {
	SendReceive(rpcDataPackage *RpcDataPackage) (*RpcDataPackage, error)
	Send(rpcDataPackage *RpcDataPackage) error
	Receive() (*RpcDataPackage, error)
	Close() error
	Reconnect() error
}

Connection handler interface

func NewBatchTCPConnection

func NewBatchTCPConnection(urls []URL, timeout time.Duration) ([]Connection, error)

NewBatchTCPConnection to create batch connection

type ConnectionPoolFactory

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

func (*ConnectionPoolFactory) ActivateObject

func (c *ConnectionPoolFactory) ActivateObject(ctx context.Context, object *pool.PooledObject) error

func (*ConnectionPoolFactory) DestroyObject

func (c *ConnectionPoolFactory) DestroyObject(ctx context.Context, object *pool.PooledObject) error

func (*ConnectionPoolFactory) MakeObject

func (*ConnectionPoolFactory) PassivateObject

func (c *ConnectionPoolFactory) PassivateObject(ctx context.Context, object *pool.PooledObject) error

func (*ConnectionPoolFactory) ValidateObject

func (c *ConnectionPoolFactory) ValidateObject(ctx context.Context, object *pool.PooledObject) bool

type ConnectionTester

type ConnectionTester interface {
	TestConnection() error
}

type DefaultService

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

DefaultService default implemention for Service interface

func (*DefaultService) DoService

func (s *DefaultService) DoService(message proto.Message, attachment []byte, logId *int64) (proto.Message, []byte, error)

DoService do call back function on RPC invocation

func (*DefaultService) GetMethodName

func (s *DefaultService) GetMethodName() string

GetMethodName get method name

func (*DefaultService) GetServiceName

func (s *DefaultService) GetServiceName() string

GetServiceName get service name

func (*DefaultService) NewParameter

func (s *DefaultService) NewParameter() proto.Message

NewParameter no long will be used

type ErrorContext added in v1.0.6

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

ErrorContext

type HaRpcClient

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

HaRpcClient high avialbe RpcClient

func NewHaRpcCient

func NewHaRpcCient(connections []Connection) (*HaRpcClient, error)

NewHaRpcCient

func NewHaRpcCientWithTimewheelSetting added in v1.1.1

func NewHaRpcCientWithTimewheelSetting(connections []Connection, timewheelInterval time.Duration, timewheelSlot uint16) (*HaRpcClient, error)

NewHaRpcCient

func (*HaRpcClient) Close added in v1.1.1

func (c *HaRpcClient) Close()

Close do close all client

func (*HaRpcClient) SendRpcRequest

func (c *HaRpcClient) SendRpcRequest(rpcInvocation *RpcInvocation, responseMessage proto.Message) (*RpcDataPackage, error)

SendRpcRequest send rpc request by elect one client

func (*HaRpcClient) SendRpcRequestWithTimeout added in v1.1.1

func (c *HaRpcClient) SendRpcRequestWithTimeout(timeout time.Duration, rpcInvocation *RpcInvocation, responseMessage proto.Message) (*RpcDataPackage, error)

SendRpcRequest send rpc request by elect one client with timeout feature

type Header struct {
	MagicCode   []byte
	MessageSize int32
	MetaSize    int32
}

RPC header content

func EmptyHead

func EmptyHead() *Header

EmptyHead return a empty head with default value

func (*Header) GetMagicCode

func (h *Header) GetMagicCode() []byte

func (*Header) GetMessageSize

func (h *Header) GetMessageSize() int32

func (*Header) GetMetaSize

func (h *Header) GetMetaSize() int32

func (*Header) Read

func (h *Header) Read(bytes []byte) error

Read read byte array

func (*Header) SetMagicCode

func (h *Header) SetMagicCode(MagicCode []byte)

func (*Header) SetMessageSize

func (h *Header) SetMessageSize(MessageSize int32)

func (*Header) SetMetaSize

func (h *Header) SetMetaSize(MetaSize int32)

func (*Header) Write

func (h *Header) Write() ([]byte, error)

Convert Header struct to byte array

type HttpServer added in v1.1.3

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

func (*HttpServer) ServeHTTP added in v1.1.3

func (h *HttpServer) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP to serve http reqeust and response to process http rpc handle

type HttpStatusView added in v1.0.11

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

HttpStatusView

func (*HttpStatusView) QpsDataStatus added in v1.0.11

func (hsv *HttpStatusView) QpsDataStatus(c context.Context, method *RPCMethod) (*QpsData, context.Context)

func (*HttpStatusView) Status added in v1.0.11

type PbFieldMeta added in v1.0.12

type PbFieldMeta struct {
	Name         string         `json:"name,omitempty"`
	Tag          int            `json:"tag,omitempty"`
	Type         string         `json:"type,omitempty"`
	Opt          string         `json:"opt,omitempty"`     // opt or req
	Version      string         `json:"version,omitempty"` // proto2 or proto3
	SubFieldMeta []*PbFieldMeta `json:"sub_field_meta,omitempty"`
	HasSub       bool           `json:"has_sub,omitempty"`
}

type QpsData added in v1.0.11

type QpsData struct {
	Qpsinfo map[int64]int32 `` /* 157-byte string literal not displayed */
	// contains filtered or unexported fields
}

func (*QpsData) Descriptor deprecated added in v1.3.0

func (*QpsData) Descriptor() ([]byte, []int)

Deprecated: Use QpsData.ProtoReflect.Descriptor instead.

func (*QpsData) GetQpsinfo added in v1.3.0

func (x *QpsData) GetQpsinfo() map[int64]int32

func (*QpsData) ProtoMessage added in v1.0.11

func (*QpsData) ProtoMessage()

func (*QpsData) ProtoReflect added in v1.3.0

func (x *QpsData) ProtoReflect() protoreflect.Message

func (*QpsData) Reset added in v1.0.11

func (x *QpsData) Reset()

func (*QpsData) String added in v1.0.11

func (x *QpsData) String() string

type RPCFN

type RPCFN func(msg proto.Message, attachment []byte, logId *int64) (proto.Message, []byte, error)

type RPCMethod added in v1.0.11

type RPCMethod struct {
	Service        string `protobuf:"bytes,1,opt,name=service,proto3" json:"service,omitempty"`
	Method         string `protobuf:"bytes,2,opt,name=method,proto3" json:"method,omitempty"`
	InTypeMeta     string `protobuf:"bytes,3,opt,name=intype,proto3" json:"intype,omitempty"`
	ReturnTypeMeta string `protobuf:"bytes,4,opt,name=returntype,proto3" json:"returntype,omitempty"`
	// contains filtered or unexported fields
}

func (*RPCMethod) Descriptor deprecated added in v1.3.0

func (*RPCMethod) Descriptor() ([]byte, []int)

Deprecated: Use RPCMethod.ProtoReflect.Descriptor instead.

func (*RPCMethod) GetInTypeMeta added in v1.3.0

func (x *RPCMethod) GetInTypeMeta() string

func (*RPCMethod) GetMethod added in v1.3.0

func (x *RPCMethod) GetMethod() string

func (*RPCMethod) GetReturnTypeMeta added in v1.3.0

func (x *RPCMethod) GetReturnTypeMeta() string

func (*RPCMethod) GetService added in v1.3.0

func (x *RPCMethod) GetService() string

func (*RPCMethod) ProtoMessage added in v1.0.11

func (*RPCMethod) ProtoMessage()

func (*RPCMethod) ProtoReflect added in v1.3.0

func (x *RPCMethod) ProtoReflect() protoreflect.Message

func (*RPCMethod) Reset added in v1.0.11

func (x *RPCMethod) Reset()

func (*RPCMethod) String added in v1.0.11

func (x *RPCMethod) String() string

type RPCMethodReuqestStatus added in v1.0.11

type RPCMethodReuqestStatus struct {
	QpsStatus map[int64]int32
}

RPCMethodReuqestStatus

type RPCRequestStatus added in v1.0.11

type RPCRequestStatus struct {
	Methods map[string]*RPCMethodReuqestStatus
	// contains filtered or unexported fields
}

RPCRequestStatus

func NewRPCRequestStatus added in v1.0.11

func NewRPCRequestStatus(services map[string]Service) *RPCRequestStatus

NewRPCRequestStatus

func (*RPCRequestStatus) RequestIn added in v1.0.11

func (r *RPCRequestStatus) RequestIn(methodName string, t time.Time, count int) error

RequestIn

func (*RPCRequestStatus) Start added in v1.0.11

func (r *RPCRequestStatus) Start() error

Start

func (*RPCRequestStatus) Stop added in v1.1.1

func (r *RPCRequestStatus) Stop()

Stop

type RPCStatus added in v1.0.11

type RPCStatus struct {
	Host            string       `protobuf:"bytes,1,opt,name=host,proto3" json:"host,omitempty"`
	Port            int32        `protobuf:"varint,2,opt,name=port,proto3" json:"port,omitempty"`
	TimeoutSenconds int32        `protobuf:"varint,3,opt,name=timeout,proto3" json:"timeout,omitempty"`
	Methods         []*RPCMethod `protobuf:"bytes,4,rep,name=methods,proto3" json:"methods,omitempty"`
	// contains filtered or unexported fields
}

func (*RPCStatus) Descriptor deprecated added in v1.3.0

func (*RPCStatus) Descriptor() ([]byte, []int)

Deprecated: Use RPCStatus.ProtoReflect.Descriptor instead.

func (*RPCStatus) GetHost added in v1.3.0

func (x *RPCStatus) GetHost() string

func (*RPCStatus) GetMethods added in v1.3.0

func (x *RPCStatus) GetMethods() []*RPCMethod

func (*RPCStatus) GetPort added in v1.3.0

func (x *RPCStatus) GetPort() int32

func (*RPCStatus) GetTimeout added in v1.3.0

func (x *RPCStatus) GetTimeout() int32

func (*RPCStatus) ProtoMessage added in v1.0.11

func (*RPCStatus) ProtoMessage()

func (*RPCStatus) ProtoReflect added in v1.3.0

func (x *RPCStatus) ProtoReflect() protoreflect.Message

func (*RPCStatus) Reset added in v1.0.11

func (x *RPCStatus) Reset()

func (*RPCStatus) String added in v1.0.11

func (x *RPCStatus) String() string

type Readable

type Readable interface {
	Read(bytes []byte) error
}

Readable is the interface that deserialize from []byte if errror ocurres should return non-nil error

type Request

type Request struct {
	ServiceName       string                    `protobuf:"bytes,1,opt,name=service_name,json=serviceName,proto3" json:"service_name,omitempty"`
	MethodName        string                    `protobuf:"bytes,2,opt,name=method_name,json=methodName,proto3" json:"method_name,omitempty"`
	LogId             int64                     `protobuf:"varint,3,opt,name=log_id,json=logId,proto3" json:"log_id,omitempty"`
	TraceId           int64                     `protobuf:"varint,4,opt,name=traceId,proto3" json:"traceId,omitempty"`
	SpanId            int64                     `protobuf:"varint,5,opt,name=spanId,proto3" json:"spanId,omitempty"`
	ParentSpanId      int64                     `protobuf:"varint,6,opt,name=parentSpanId,proto3" json:"parentSpanId,omitempty"`
	RpcRequestMetaExt []*RpcRequestMetaExtField `protobuf:"bytes,7,rep,name=rpcRequestMetaExt,proto3" json:"rpcRequestMetaExt,omitempty"`
	ExtraParam        []byte                    `protobuf:"bytes,110,opt,name=extraParam,proto3" json:"extraParam,omitempty"`
	// contains filtered or unexported fields
}

func (*Request) Descriptor deprecated

func (*Request) Descriptor() ([]byte, []int)

Deprecated: Use Request.ProtoReflect.Descriptor instead.

func (*Request) GetExtraParam

func (x *Request) GetExtraParam() []byte

func (*Request) GetLogId

func (x *Request) GetLogId() int64

func (*Request) GetMethodName

func (x *Request) GetMethodName() string

func (*Request) GetParentSpanId added in v1.3.0

func (x *Request) GetParentSpanId() int64

func (*Request) GetRpcRequestMetaExt added in v1.3.0

func (x *Request) GetRpcRequestMetaExt() []*RpcRequestMetaExtField

func (*Request) GetServiceName

func (x *Request) GetServiceName() string

func (*Request) GetSpanId added in v1.3.0

func (x *Request) GetSpanId() int64

func (*Request) GetTraceId added in v1.3.0

func (x *Request) GetTraceId() int64

func (*Request) ProtoMessage

func (*Request) ProtoMessage()

func (*Request) ProtoReflect added in v1.3.0

func (x *Request) ProtoReflect() protoreflect.Message

func (*Request) Reset

func (x *Request) Reset()

func (*Request) String

func (x *Request) String() string

type Response

type Response struct {
	ErrorCode int32  `protobuf:"varint,1,opt,name=error_code,json=errorCode,proto3" json:"error_code,omitempty"`
	ErrorText string `protobuf:"bytes,2,opt,name=error_text,json=errorText,proto3" json:"error_text,omitempty"`
	// contains filtered or unexported fields
}

func (*Response) Descriptor deprecated

func (*Response) Descriptor() ([]byte, []int)

Deprecated: Use Response.ProtoReflect.Descriptor instead.

func (*Response) GetErrorCode

func (x *Response) GetErrorCode() int32

func (*Response) GetErrorText

func (x *Response) GetErrorText() string

func (*Response) ProtoMessage

func (*Response) ProtoMessage()

func (*Response) ProtoReflect added in v1.3.0

func (x *Response) ProtoReflect() protoreflect.Message

func (*Response) Reset

func (x *Response) Reset()

func (*Response) String

func (x *Response) String() string

type ResponseData added in v1.1.3

type ResponseData struct {
	ErrNo   int         `json:"errno"`
	Message string      `json:"message,omitempty"`
	Data    interface{} `json:"data,omitempty"`
}

ResponseData

type RpcClient

type RpcClient struct {
	Session Connection
	// contains filtered or unexported fields
}

RPC client invoke

func NewRpcCient

func NewRpcCient(connection Connection) (*RpcClient, error)

NewRpcCient new rpc client

func NewRpcCientWithTimeWheelSetting added in v1.1.1

func NewRpcCientWithTimeWheelSetting(connection Connection, timewheelInterval time.Duration, timewheelSlot uint16) (*RpcClient, error)

NewRpcCientWithTimeWheelSetting new rpc client with set timewheel settings

func (*RpcClient) Close added in v1.1.1

func (c *RpcClient) Close()

define client methods Close close client with time wheel

func (*RpcClient) SendRpcRequest

func (c *RpcClient) SendRpcRequest(rpcInvocation *RpcInvocation, responseMessage proto.Message) (*RpcDataPackage, error)

SendRpcRequest send rpc request to remote server

func (*RpcClient) SendRpcRequestAsyc added in v1.1.1

func (c *RpcClient) SendRpcRequestAsyc(rpcInvocation *RpcInvocation, responseMessage proto.Message) <-chan *RpcResult

SendRpcRequestAsyc send rpc request to remote server in asynchronous way

func (*RpcClient) SendRpcRequestWithTimeout added in v1.1.1

func (c *RpcClient) SendRpcRequestWithTimeout(timeout time.Duration, rpcInvocation *RpcInvocation, responseMessage proto.Message) (*RpcDataPackage, error)

SendRpcRequest send rpc request to remote server

type RpcDataPackage

type RpcDataPackage struct {
	Head       *Header  // rpc head
	Meta       *RpcMeta // rpc meta
	Data       []byte
	Attachment []byte
	// contains filtered or unexported fields
}
Data package for baidu RPC.
all request and response data package should apply this.

----------------------------------- | Head | Meta | Data | Attachment | -----------------------------------

1. <Head> with fixed 12 byte length as follow format ---------------------------------------------- | PRPC | MessageSize(int32) | MetaSize(int32) | ---------------------------------------------- MessageSize = totalSize - 12(Fixed Head Size) MetaSize = Meta object size

2. <Meta> body proto description as follow

message RpcMeta {
    optional Request request = 1;
    optional Response response = 2;
    optional int32 compress_type = 3; // 0:nocompress 1:Snappy 2:gzip
    optional int64 correlation_id = 4;
    optional int32 attachment_size = 5;
    optional ChuckInfo chuck_info = 6;
    optional bytes authentication_data = 7;
};
message Request {
    required string service_name = 1;
    required string method_name = 2;
    optional int64 log_id = 3;
	optional int64 traceId=4;
	optional int64 spanId=5;
	optional int64 parentSpanId=6;
	repeat RpcRequestMetaExtField extFields = 7;
};
message RpcRequestMetaExtField {
	optional string key = 1;
	optional string value = 2;
}
message Response {
    optional int32 error_code = 1;
    optional string error_text = 2;
};
messsage ChuckInfo {
    required int64 stream_id = 1;
    required int64 chunk_id = 2;
};

3. <Data> customize transport data message.

4. <Attachment> attachment body data message

func NewRpcDataPackage

func NewRpcDataPackage() *RpcDataPackage

func (*RpcDataPackage) AuthenticationData

func (r *RpcDataPackage) AuthenticationData(authenticationData []byte) *RpcDataPackage

func (*RpcDataPackage) ChuckInfo added in v1.3.0

func (r *RpcDataPackage) ChuckInfo(streamId int64, chunkId int64) *RpcDataPackage

func (*RpcDataPackage) Chunk added in v1.1.1

func (r *RpcDataPackage) Chunk(chunkSize int) []*RpcDataPackage

Chunk chunk to small packages by chunk size

func (*RpcDataPackage) ClearChunkStatus added in v1.1.1

func (r *RpcDataPackage) ClearChunkStatus()

func (*RpcDataPackage) CompressType

func (r *RpcDataPackage) CompressType(compressType int32) *RpcDataPackage

func (*RpcDataPackage) CorrelationId

func (r *RpcDataPackage) CorrelationId(correlationId int64) *RpcDataPackage

func (*RpcDataPackage) ErrorCode

func (r *RpcDataPackage) ErrorCode(errorCode int32) *RpcDataPackage

func (*RpcDataPackage) ErrorText

func (r *RpcDataPackage) ErrorText(errorText string) *RpcDataPackage

func (*RpcDataPackage) ExtraParams

func (r *RpcDataPackage) ExtraParams(extraParams []byte) *RpcDataPackage

func (*RpcDataPackage) GetAttachment

func (r *RpcDataPackage) GetAttachment() []byte

func (*RpcDataPackage) GetChunkStreamId added in v1.1.1

func (r *RpcDataPackage) GetChunkStreamId() int64

GetChunkStreamId

func (*RpcDataPackage) GetData

func (r *RpcDataPackage) GetData() []byte

func (*RpcDataPackage) GetHead

func (r *RpcDataPackage) GetHead() *Header

func (*RpcDataPackage) GetLogId

func (r *RpcDataPackage) GetLogId() int64

func (*RpcDataPackage) GetMagicCode

func (r *RpcDataPackage) GetMagicCode() string

func (*RpcDataPackage) GetMeta

func (r *RpcDataPackage) GetMeta() *RpcMeta

func (*RpcDataPackage) GetParentSpanId added in v1.1.1

func (r *RpcDataPackage) GetParentSpanId() int64

func (*RpcDataPackage) GetRpcRequestMetaExt added in v1.1.1

func (r *RpcDataPackage) GetRpcRequestMetaExt() map[string]string

func (*RpcDataPackage) GetSpanId added in v1.1.1

func (r *RpcDataPackage) GetSpanId() int64

func (*RpcDataPackage) GetTraceId added in v1.1.1

func (r *RpcDataPackage) GetTraceId() int64

func (*RpcDataPackage) IsChunkPackage added in v1.1.1

func (r *RpcDataPackage) IsChunkPackage() bool

IsChunkPackage

func (*RpcDataPackage) IsFinalPackage added in v1.1.1

func (r *RpcDataPackage) IsFinalPackage() bool

IsFinalPackage

func (*RpcDataPackage) LogId

func (r *RpcDataPackage) LogId(logId int64) *RpcDataPackage

func (*RpcDataPackage) MagicCode

func (r *RpcDataPackage) MagicCode(magicCode string)

func (*RpcDataPackage) MethodName

func (r *RpcDataPackage) MethodName(methodName string) *RpcDataPackage

func (*RpcDataPackage) ParentSpanId added in v1.1.1

func (r *RpcDataPackage) ParentSpanId(parentSpanId int64) *RpcDataPackage

func (*RpcDataPackage) Read

func (r *RpcDataPackage) Read(b []byte) error

func (*RpcDataPackage) ReadIO

func (r *RpcDataPackage) ReadIO(rw io.Reader) error

Read byte array and initialize RpcPackage

func (*RpcDataPackage) RpcRequestMetaExt added in v1.1.1

func (r *RpcDataPackage) RpcRequestMetaExt(ext map[string]string) *RpcDataPackage

func (*RpcDataPackage) ServiceName

func (r *RpcDataPackage) ServiceName(serviceName string) *RpcDataPackage

func (*RpcDataPackage) SetAttachment

func (r *RpcDataPackage) SetAttachment(Attachment []byte) *RpcDataPackage

func (*RpcDataPackage) SetData

func (r *RpcDataPackage) SetData(Data []byte) *RpcDataPackage

func (*RpcDataPackage) SpanId added in v1.1.1

func (r *RpcDataPackage) SpanId(spanId int64) *RpcDataPackage

func (*RpcDataPackage) TraceId added in v1.1.1

func (r *RpcDataPackage) TraceId(traceId int64) *RpcDataPackage

func (*RpcDataPackage) Write

func (r *RpcDataPackage) Write() ([]byte, error)

Convert RpcPackage to byte array

func (*RpcDataPackage) WriteIO

func (r *RpcDataPackage) WriteIO(rw io.Writer) error

Convert RpcPackage to byte array

type RpcDataPackageCodec

type RpcDataPackageCodec[S, R *RpcDataPackage] struct {
	// contains filtered or unexported fields
}

Codec implements for RpcDataPackage.

func (*RpcDataPackageCodec[S, R]) Close

func (r *RpcDataPackageCodec[S, R]) Close() error

do close connection io return non-nil if any error ocurred while doing close

func (*RpcDataPackageCodec[S, R]) Receive

func (r *RpcDataPackageCodec[S, R]) Receive() (*RpcDataPackage, error)

receive serialized data to target server by connection IO return param: 1. RpcDataPackage unserialized from connection io. or nil if exception found 2. a non-nil error if any io exception occured

func (*RpcDataPackageCodec[S, R]) Send

func (r *RpcDataPackageCodec[S, R]) Send(msg *RpcDataPackage) error

send serialized data to target server by connection IO msg: param 'msg' must type of RpcDataPackage

func (*RpcDataPackageCodec[S, R]) SetTimeout

func (r *RpcDataPackageCodec[S, R]) SetTimeout(timeout *time.Duration)

set connection io read and write dead line

type RpcDataPackageProtocol

type RpcDataPackageProtocol[S, R *RpcDataPackage] struct {
	// contains filtered or unexported fields
}

Protocol codec factory object for RpcDataPackage

func NewRpcDataPackageProtocol added in v1.1.1

func NewRpcDataPackageProtocol[S, R *RpcDataPackage]() (*RpcDataPackageProtocol[S, R], error)

NewRpcDataPackageProtocol create a RpcDataPackageProtocol and start timewheel

func (*RpcDataPackageProtocol[S, R]) NewCodec

func (*RpcDataPackageProtocol[S, R]) Stop added in v1.1.1

func (r *RpcDataPackageProtocol[S, R]) Stop()

Stop

type RpcInvocation

type RpcInvocation struct {
	ServiceName       *string
	MethodName        *string
	ParameterIn       *proto.Message
	Attachment        []byte
	LogId             *int64
	CompressType      *int32
	AuthenticateData  []byte
	ChunkSize         uint32
	TraceId           int64
	SpanId            int64
	ParentSpanId      int64
	RpcRequestMetaExt map[string]string
}

RpcInvocation define rpc invocation

func NewRpcInvocation

func NewRpcInvocation(serviceName, methodName *string) *RpcInvocation

NewRpcInvocation create RpcInvocation with service name and method name

func (*RpcInvocation) GetRequestRpcDataPackage

func (r *RpcInvocation) GetRequestRpcDataPackage() (*RpcDataPackage, error)

GetRequestRpcDataPackage

func (*RpcInvocation) SetParameterIn

func (r *RpcInvocation) SetParameterIn(parameterIn proto.Message)

SetParameterIn

type RpcMeta

type RpcMeta struct {
	Request            *Request   `protobuf:"bytes,1,opt,name=request,proto3" json:"request,omitempty"`
	Response           *Response  `protobuf:"bytes,2,opt,name=response,proto3" json:"response,omitempty"`
	CompressType       int32      `protobuf:"varint,3,opt,name=compress_type,json=compressType,proto3" json:"compress_type,omitempty"` // 0:nocompress 1:Snappy 2:gzip
	CorrelationId      int64      `protobuf:"varint,4,opt,name=correlation_id,json=correlationId,proto3" json:"correlation_id,omitempty"`
	AttachmentSize     int32      `protobuf:"varint,5,opt,name=attachment_size,json=attachmentSize,proto3" json:"attachment_size,omitempty"`
	ChuckInfo          *ChunkInfo `protobuf:"bytes,6,opt,name=chuck_info,json=chuckInfo,proto3" json:"chuck_info,omitempty"`
	AuthenticationData []byte     `protobuf:"bytes,7,opt,name=authentication_data,json=authenticationData,proto3" json:"authentication_data,omitempty"`
	// contains filtered or unexported fields
}

func (*RpcMeta) Descriptor deprecated

func (*RpcMeta) Descriptor() ([]byte, []int)

Deprecated: Use RpcMeta.ProtoReflect.Descriptor instead.

func (*RpcMeta) GetAttachmentSize

func (x *RpcMeta) GetAttachmentSize() int32

func (*RpcMeta) GetAuthenticationData

func (x *RpcMeta) GetAuthenticationData() []byte

func (*RpcMeta) GetChuckInfo added in v1.3.0

func (x *RpcMeta) GetChuckInfo() *ChunkInfo

func (*RpcMeta) GetCompressType

func (x *RpcMeta) GetCompressType() int32

func (*RpcMeta) GetCorrelationId

func (x *RpcMeta) GetCorrelationId() int64

func (*RpcMeta) GetRequest

func (x *RpcMeta) GetRequest() *Request

func (*RpcMeta) GetResponse

func (x *RpcMeta) GetResponse() *Response

func (*RpcMeta) ProtoMessage

func (*RpcMeta) ProtoMessage()

func (*RpcMeta) ProtoReflect added in v1.3.0

func (x *RpcMeta) ProtoReflect() protoreflect.Message

func (*RpcMeta) Reset

func (x *RpcMeta) Reset()

func (*RpcMeta) String

func (x *RpcMeta) String() string

type RpcRequestMetaExtField added in v1.1.1

type RpcRequestMetaExtField struct {
	Key   string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
	Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"`
	// contains filtered or unexported fields
}

func (*RpcRequestMetaExtField) Descriptor deprecated added in v1.3.0

func (*RpcRequestMetaExtField) Descriptor() ([]byte, []int)

Deprecated: Use RpcRequestMetaExtField.ProtoReflect.Descriptor instead.

func (*RpcRequestMetaExtField) GetKey added in v1.1.1

func (x *RpcRequestMetaExtField) GetKey() string

func (*RpcRequestMetaExtField) GetValue added in v1.1.1

func (x *RpcRequestMetaExtField) GetValue() string

func (*RpcRequestMetaExtField) ProtoMessage added in v1.1.1

func (*RpcRequestMetaExtField) ProtoMessage()

func (*RpcRequestMetaExtField) ProtoReflect added in v1.3.0

func (x *RpcRequestMetaExtField) ProtoReflect() protoreflect.Message

func (*RpcRequestMetaExtField) Reset added in v1.1.1

func (x *RpcRequestMetaExtField) Reset()

func (*RpcRequestMetaExtField) String added in v1.1.1

func (x *RpcRequestMetaExtField) String() string

type RpcResult added in v1.1.1

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

RpcResult Rpc response result from client request api under asynchronous way

func (*RpcResult) Get added in v1.1.1

func (rr *RpcResult) Get() proto.Message

func (*RpcResult) GetErr added in v1.1.1

func (rr *RpcResult) GetErr() error

func (*RpcResult) GetRpcDataPackage added in v1.1.1

func (rr *RpcResult) GetRpcDataPackage() *RpcDataPackage

type Server

type Server interface {
	Start() error
	Stop() error
	Register(service *Service) (bool, error)
}

type ServerMeta

type ServerMeta struct {
	Host               *string
	Port               *int
	IdleTimeoutSeconds *int
	QPSExpireInSecs    int
	ChunkSize          uint32
	TimeoutSeconds     uint32
}

type Service

type Service interface {
	/*
	   RPC service call back method.
	   message : parameter in from RPC client or 'nil' if has no parameter
	   attachment : attachment content from RPC client or 'nil' if has no attachment
	   logId : with a int64 type log sequence id from client or 'nil if has no logId
	   return:
	   [0] message return back to RPC client or 'nil' if need not return method response
	   [1] attachment return back to RPC client or 'nil' if need not return attachemnt
	   [2] return with any error or 'nil' represents success
	*/
	DoService(message proto.Message, attachment []byte, logId *int64) (proto.Message, []byte, error)
	GetServiceName() string
	GetMethodName() string
	NewParameter() proto.Message
}

Service rpc service

type TCPConnection

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

TCPConnection simple tcp based connection implementation

func NewTCPConnection

func NewTCPConnection(url URL, timeout *time.Duration) (*TCPConnection, error)

Create a new TCPConnection and try to connect to target server by URL.

func (*TCPConnection) Close

func (c *TCPConnection) Close() error

Close close connection

func (*TCPConnection) GetId

func (c *TCPConnection) GetId() uint64

func (*TCPConnection) Receive added in v1.1.1

func (c *TCPConnection) Receive() (*RpcDataPackage, error)

Receive data from connection

func (*TCPConnection) Reconnect added in v1.2.1

func (c *TCPConnection) Reconnect() error

Reconnect do connect by saved info

func (*TCPConnection) Send added in v1.1.1

func (c *TCPConnection) Send(rpcDataPackage *RpcDataPackage) error

Send data to connection

func (*TCPConnection) SendReceive

func (c *TCPConnection) SendReceive(rpcDataPackage *RpcDataPackage) (*RpcDataPackage, error)

SendReceive send data to connect and block wait data recevie

func (*TCPConnection) TestConnection

func (c *TCPConnection) TestConnection() error

type TCPConnectionPool

type TCPConnectionPool struct {
	Config *pool.ObjectPoolConfig
	// contains filtered or unexported fields
}

func NewDefaultTCPConnectionPool

func NewDefaultTCPConnectionPool(url URL, timeout *time.Duration) (*TCPConnectionPool, error)

func NewTCPConnectionPool

func NewTCPConnectionPool(url URL, timeout *time.Duration, config *pool.ObjectPoolConfig) (*TCPConnectionPool, error)

func (*TCPConnectionPool) Close

func (c *TCPConnectionPool) Close() error

func (*TCPConnectionPool) GetNumActive

func (c *TCPConnectionPool) GetNumActive() int

func (*TCPConnectionPool) Receive added in v1.1.1

func (c *TCPConnectionPool) Receive() (*RpcDataPackage, error)

Receive

func (*TCPConnectionPool) Reconnect added in v1.2.1

func (c *TCPConnectionPool) Reconnect() error

Reconnect do connect by saved info

func (*TCPConnectionPool) Send added in v1.1.1

func (c *TCPConnectionPool) Send(rpcDataPackage *RpcDataPackage) error

Send

func (*TCPConnectionPool) SendReceive

func (c *TCPConnectionPool) SendReceive(rpcDataPackage *RpcDataPackage) (*RpcDataPackage, error)

type TcpServer

type TcpServer struct {
	EnablePerformanceLog bool
	// contains filtered or unexported fields
}

TcpServer RPC server base on tcp transport

func NewTpcServer

func NewTpcServer(serverMeta *ServerMeta) *TcpServer

NewTpcServer

func (*TcpServer) EnableHttp added in v1.1.3

func (s *TcpServer) EnableHttp()

EnableHttp

func (*TcpServer) Register

func (s *TcpServer) Register(service interface{}) (bool, error)

Register register RPC service

func (*TcpServer) RegisterName

func (s *TcpServer) RegisterName(name string, rcvr interface{}) (bool, error)

RegisterName register publishes in the server with specified name for its set of methods of the receiver value that satisfy the following conditions:

  • exported method of exported type
  • one argument, exported type and should be the type implements from proto.Message
  • one return value, of type proto.Message

It returns an error if the receiver is not an exported type or has no suitable methods. It also logs the error using package log. The client accesses each method using a string of the form "Type.Method", where Type is the receiver's concrete type.

func (*TcpServer) RegisterNameWithMethodMapping

func (s *TcpServer) RegisterNameWithMethodMapping(name string, rcvr interface{}, mapping map[string]string) (bool, error)

RegisterNameWithMethodMapping call RegisterName with method name mapping map

func (*TcpServer) RegisterRpc

func (s *TcpServer) RegisterRpc(sname, mname string, callback RPCFN, inType proto.Message) (bool, error)

RegisterRpc register Rpc direct

func (*TcpServer) SetAuthService added in v1.1.1

func (s *TcpServer) SetAuthService(authservice AuthService)

SetAuthService set authenticate service

func (*TcpServer) SetTraceService added in v1.1.1

func (s *TcpServer) SetTraceService(traceService TraceService)

SetTraceService set trace service

func (*TcpServer) Start

func (s *TcpServer) Start() error

func (*TcpServer) StartAndBlock

func (s *TcpServer) StartAndBlock() error

func (*TcpServer) StartServer added in v1.0.8

func (s *TcpServer) StartServer(l net.Listener) error

StartServer start server with net.Listener

func (*TcpServer) Stop

func (s *TcpServer) Stop(ctx context.Context) error

Stop do stop rpc server

type TraceInfo added in v1.1.1

type TraceInfo struct {
	TraceId           int64
	SpanId            int64
	ParentSpanId      int64
	RpcRequestMetaExt map[string]string
}

type TraceService added in v1.1.1

type TraceService interface {
	Trace(service, name string, traceInfo *TraceInfo) *TraceInfo
}

TraceService to monitor trace info and return trace info back

type URL

type URL struct {
	Host *string
	Port *int
}

URL with host and port attribute

func (*URL) SetHost

func (u *URL) SetHost(host *string) *URL

SetHost set host name

func (*URL) SetPort

func (u *URL) SetPort(port *int) *URL

SetPort set port

type Writable

type Writable interface {
	Write() ([]byte, error)
}

Writable is the interface that do serialize to []byte if errror ocurres should return non-nil error

Directories

Path Synopsis
Go support for Protocol Buffers RPC which compatiable with https://github.com/Baidu-ecom/Jprotobuf-rpc-socket
Go support for Protocol Buffers RPC which compatiable with https://github.com/Baidu-ecom/Jprotobuf-rpc-socket

Jump to

Keyboard shortcuts

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