Documentation ¶
Overview ¶
Package inprocgrpc provides an in-process gRPC channel implementation. The in-process channel makes RPCs that are effectively in-process function calls. The function calls run in a separate goroutine from the caller so as to fully behave like a normal RPC call, including context deadlines and cancellations. This can be useful for same-process hand-off to RPC endpoints and for testing. It has less overhead than using a loopback socket connection as it elides marshaling to bytes and back.
Index ¶
- type Channel
- func (c *Channel) Invoke(ctx context.Context, method string, req, resp interface{}, ...) error
- func (c *Channel) NewStream(ctx context.Context, desc *grpc.StreamDesc, method string, ...) (grpc.ClientStream, error)
- func (c *Channel) RegisterService(desc *grpc.ServiceDesc, svr interface{})
- func (c *Channel) WithServerStreamInterceptor(interceptor grpc.StreamServerInterceptor) *Channel
- func (c *Channel) WithServerUnaryInterceptor(interceptor grpc.UnaryServerInterceptor) *Channel
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Channel ¶
type Channel struct {
// contains filtered or unexported fields
}
Channel is a gRPC channel where RPCs amount to an in-process method call. This is in contrast to a normal gRPC channel, where request messages marshaled to another process over a TCP socket and responses unmarshaled from the same socket.
So the in-process channel functions as both a client channel AND a server. It handles method calls from a gRPC client stub and then delivers them directly to a registered server implementation.
The server-side of an RPC is executed in a separate goroutine, so things like deadlines and context cancellation work, even for unary RPCs.
func (*Channel) Invoke ¶
func (c *Channel) Invoke(ctx context.Context, method string, req, resp interface{}, opts ...grpc.CallOption) error
Invoke satisfies the grpchan.Channel interface and supports sending unary RPCs via the in-process channel.
func (*Channel) NewStream ¶
func (c *Channel) NewStream(ctx context.Context, desc *grpc.StreamDesc, method string, opts ...grpc.CallOption) (grpc.ClientStream, error)
NewStream satisfies the grpchan.Channel interface and supports sending streaming RPCs via the in-process channel.
func (*Channel) RegisterService ¶
func (c *Channel) RegisterService(desc *grpc.ServiceDesc, svr interface{})
RegisterService registers the given service and implementation. Like a normal gRPC server, an in-process channel only allows a single implementation for a particular service. Services are identified by their fully-qualified name (e.g. "<package>.<service>").
func (*Channel) WithServerStreamInterceptor ¶
func (c *Channel) WithServerStreamInterceptor(interceptor grpc.StreamServerInterceptor) *Channel
WithServerStreamInterceptor configures the in-process channel to use the given server interceptor for streaming RPCs when dispatching.
func (*Channel) WithServerUnaryInterceptor ¶
func (c *Channel) WithServerUnaryInterceptor(interceptor grpc.UnaryServerInterceptor) *Channel
WithServerUnaryInterceptor configures the in-process channel to use the given server interceptor for unary RPCs when dispatching.