serverfunk

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package serverfunk contains types that comes in handy when writing servers.

Index

Constants

View Source
const LocalShard = -1

LocalShard is a return value to the ShardConversionFunc if you want processing to be on the local node. With a round robin load balancer this will be evenly distributed on all nodes.

Variables

This section is empty.

Functions

func UnaryInterceptor added in v0.0.22

func UnaryInterceptor(cluster funk.Cluster, shardFn ShardConversionFunc, clientProxy *ProxyConnections, metricsType string) grpc.UnaryServerInterceptor

UnaryInterceptor returns the bare grpc.UnaryInterceptor used to route requests to the various nodes. If you need more than one interceptor you have to chain them and build the server option list manually.

func WithClusterFunk

func WithClusterFunk(cluster funk.Cluster, shardFn ShardConversionFunc, clientProxy *ProxyConnections, metricsType string) []grpc.ServerOption

WithClusterFunk returns server options for Clusterfunk gRPC servers. This will add a stream and unary interceptor to the server that will proxy the requests to the correct peer. The metrics string is the one used in the Parameters struct from the funk package. Streams are not proxied.

Types

type ProxyConnections

type ProxyConnections struct {
	Shards       sharding.ShardMap
	Cluster      funk.Cluster
	EndpointName string
	// contains filtered or unexported fields
}

ProxyConnections manages grpc.ClientConn connections to proxies.

func NewProxyConnections

func NewProxyConnections(endpointName string, shards sharding.ShardMap, cluster funk.Cluster) *ProxyConnections

NewProxyConnections creates a new GRPCClientProxy

func (*ProxyConnections) GetConnection

func (p *ProxyConnections) GetConnection(shard int) (*grpc.ClientConn, string, error)

GetConnection returns a gRPC connection and node ID to the service handling the shard (ID). If the shard is handled locally it will return a nil connection

func (*ProxyConnections) Options

func (p *ProxyConnections) Options() []grpc.DialOption

Options returns the grpc.DialOption to use when creating new connections

type ShardConversionFunc

type ShardConversionFunc func(request interface{}) (shard int, response interface{})

ShardConversionFunc is the shard conversion function, ie return a shard based on the request parameter to the gRPC server methods. It will also return the expected response object for the request. If the shard is a negative value the local node is used.

Jump to

Keyboard shortcuts

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