brpc

package module
v0.0.0-...-3b6a1d2 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

README

bRPC-Go

The Go implementation of bRPC.

Prerequisites

  • Go

  • Protocol buffer compiler, protoc

  • Go plugins for the protocol compiler:

    $ go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28
    $ go install github.com/xxpbb/brpc-go/cmd/protoc-gen-go-brpc@latest
    

Installation

With Go module support (Go 1.11+), simply add the following import

import "github.com/xxpbb/brpc-go"

to your code, and then go [build|run|test] will automatically fetch the necessary dependencies.

Documentation

Index

Constants

View Source
const (
	SupportPackageIsVersion1 = true
)

The SupportPackageIsVersion variables are referenced from generated protocol buffer files to ensure compatibility with the bRPC version used. The latest support package version is 1.

Older versions are kept for compatibility.

These constants should not be referenced from any other code.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallOption

type CallOption interface {
	// contains filtered or unexported methods
}

CallOption configure a Call before it starts or extracts information from a Call after it completes.

func WithRequestAttachment

func WithRequestAttachment(a []byte) CallOption

func WithResponseAttachment

func WithResponseAttachment(a *[]byte) CallOption

type ClientConn

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

ClientConn represents a virtual connection to a conceptual endpoint, to perform RPCs.

A ClientConn is free to have zero or more actual connections to the endpoint based on configuration, load, etc. It is also free to determine which actual endpoints to use and may change it every RPC, permitting client-side load balancing.

A ClientConn encapsulates a range of functionality including name resolution, TCP connection establishment (with retries and backoff) and TLS handshakes. It also handles errors on established connections by re-resolving the name and reconnecting.

func Dial

func Dial(target string, opts ...DialOption) (*ClientConn, error)

Dial creates a client connection to the given target.

func DialContext

func DialContext(ctx context.Context, target string, opts ...DialOption) (*ClientConn, error)

DialContext creates a client connection to the given target. By default, it's a non-blocking dial (the function won't wait for connections to be established, and connecting happens in the background). To make it a blocking dial, use WithBlock() dial option.

In the non-blocking case, the ctx does not act against the connection. It only controls the setup steps.

In the blocking case, ctx can be used to cancel or expire the pending connection. Once this function returns, the cancellation and expiration of ctx will be noop. Users should call ClientConn.Close to terminate all the pending operations after this function returns.

The target name syntax is defined in https://github.com/grpc/grpc/blob/master/doc/naming.md. e.g. to use dns resolver, a "dns:///" prefix should be applied to the target.

func (*ClientConn) Close

func (cc *ClientConn) Close() error

Close tears down the ClientConn and all underlying connections.

func (*ClientConn) Connect

func (cc *ClientConn) Connect() error

Connect causes all subchannels in the ClientConn to attempt to connect if the channel is idle.

func (*ClientConn) Invoke

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

Invoke sends the RPC request on the wire and returns after response is received. This is typically called by generated code.

All errors returned by Invoke are compatible with the status package.

type ClientConnInterface

type ClientConnInterface interface {
	Invoke(ctx context.Context, method string, args interface{}, reply interface{}, opts ...CallOption) error
}

ClientConnInterface defines the functions clients need to perform unary RPCs. It is implemented by *clientConn, and is only intended to be referenced by generated code.

type Controller

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

A Controller mediates a single method call. The primary purpose of the controller is to provide a way to manipulate settings per RPC-call and to find out about RPC-level errors.

func GetControllerFromContext

func GetControllerFromContext(ctx context.Context) *Controller

func (*Controller) GetRequestAttachment

func (c *Controller) GetRequestAttachment() []byte

func (*Controller) SetResponseAttachment

func (c *Controller) SetResponseAttachment(a []byte)

type DialOption

type DialOption interface {
	// contains filtered or unexported methods
}

DialOption configure how we set up the connection.

func WithDefaultCallOptions

func WithDefaultCallOptions(cos ...CallOption) DialOption

WithDefaultCallOptions returns a DialOption which sets the default CallOptions for calls over the connection.

type Message

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

func NewMessage

func NewMessage() *Message

func (*Message) Decode

func (m *Message) Decode(reader netpoll.Reader) error

func (*Message) Encode

func (m *Message) Encode() (netpoll.Writer, error)

type MethodDesc

type MethodDesc struct {
	MethodName string
	Handler    methodHandler
}

MethodDesc represents an RPC service's method specification.

type Server

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

Server is a bRPC server to serve RPC requests.

func NewServer

func NewServer(opt ...ServerOption) *Server

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

func (*Server) GracefulStop

func (s *Server) GracefulStop()

func (*Server) RegisterService

func (s *Server) RegisterService(sd *ServiceDesc, ss interface{})

RegisterService registers a service and its implementation to the bRPC server. It is called from the IDL generated code. This must be called before invoking Serve. If ss is non-nil (for legacy code), its type is checked to ensure it implements sd.HandlerType.

func (*Server) Serve

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

Serve accepts incoming connections on the listener lis, creating a new ServerTransport and service goroutine for each. The service goroutines read bRPC requests and then call the registered handlers to reply to them. Serve returns when lis.Accept fails with fatal errors. lis will be closed when this method returns. Serve will return a non-nil error unless Stop or GracefulStop is called.

func (*Server) Stop

func (s *Server) Stop()

type ServerOption

type ServerOption interface {
	// contains filtered or unexported methods
}

A ServerOption sets options such as credentials, codec and keepalive parameters, etc.

type ServiceDesc

type ServiceDesc struct {
	ServiceName string
	// The pointer to the service interface. Used to check whether the user
	// provided implementation satisfies the interface requirements.
	HandlerType interface{}
	Methods     []MethodDesc
}

ServiceDesc represents an RPC service's specification.

type ServiceRegistrar

type ServiceRegistrar interface {
	// RegisterService registers a service and its implementation to the
	// concrete type implementing this interface.  It may not be called
	// once the server has started serving.
	// desc describes the service and its methods and handlers. impl is the
	// service implementation which is passed to the method handlers.
	RegisterService(desc *ServiceDesc, impl interface{})
}

ServiceRegistrar wraps a single method that supports service registration. It enables users to pass concrete types other than brpc.Server to the service registration methods exported by the IDL generated code.

Directories

Path Synopsis
cmd
example
echo/client command
echo/server command
Package status implements errors returned by bRPC.
Package status implements errors returned by bRPC.

Jump to

Keyboard shortcuts

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