transport

package
v2.22.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RPCBasePath is the base path for all etc based RPCs.
	RPCBasePath = "/rpc"

	// RPCRequestPath is the path for RPC requests.
	RPCRequestPath = "/request"

	// RPCResponsePath is the path for RPC responses.
	RPCResponsePath = "/response"
)

Variables

View Source
var TransportClientModule = fx.Options(
	fx.Provide(NewEtcdTransportClient),
)

TransportClientModule is the client fx provider for etcd transport.

View Source
var TransportServerModule = fx.Options(
	fx.Provide(NewEtcdTransportServer),
)

TransportServerModule is the server fx provider for etcd transport.

Functions

func RegisterFunction

func RegisterFunction[Req, Resp proto.Message](
	t *EtcdTransportClient,
	handler func(context.Context, Req) (Resp, error),
) error

RegisterFunction register a function as a handler in the registry Only one function for a given Req type can be registered.

func RegisterWatcher

func RegisterWatcher(lc fx.Lifecycle, t *EtcdTransportClient, agentName string)

RegisterWatcher allows to register a client on the etcd transport.

func SendRequest

func SendRequest[RespValue any, Resp ExactMessage[RespValue]](ctx context.Context, t *EtcdTransportServer, client string, msg proto.Message) (*RespValue, error)

SendRequest allows consumers of the etcd transport to send single request to agents.

Types

type EtcdTransportClient

type EtcdTransportClient struct {
	Registry *HandlerRegistry
	// contains filtered or unexported fields
}

EtcdTransportClient is the client side for the etcd transport.

func NewEtcdTransportClient

func NewEtcdTransportClient(client *etcdclient.Client) (*EtcdTransportClient, error)

NewEtcdTransportClient creates and returns a new etcd transport client module.

func (*EtcdTransportClient) RegisterWatcher

func (c *EtcdTransportClient) RegisterWatcher(agentName string) error

RegisterWatcher register an agent on the etcd transport client.

func (*EtcdTransportClient) Stop

func (c *EtcdTransportClient) Stop()

Stop stops the etcd transport client.

type EtcdTransportServer

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

EtcdTransportServer is the server side of the etcd transport.

func NewEtcdTransportServer

func NewEtcdTransportServer(client *etcdclient.Client) (*EtcdTransportServer, error)

NewEtcdTransportServer creates a new server on the etcd transport.

func (*EtcdTransportServer) SendRequest

func (t *EtcdTransportServer) SendRequest(ctx context.Context, client string, msg proto.Message) (*Response, error)

SendRequest sends a request to etcd, supposed to be consumed by an agent.

type ExactMessage

type ExactMessage[T any] interface {
	proto.Message
	*T
}

ExactMessage is like proto.Message, but known to point to T.

type HandlerRegistry

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

HandlerRegistry allow registering handlers and can start a dispatcher.

This is intended to be used at at fx provide/invoke stage.

func NewHandlerRegistry

func NewHandlerRegistry() *HandlerRegistry

NewHandlerRegistry creates a new HandlerRegistry.

type Request

type Request struct {
	ID     string
	Client string
	Data   []byte
}

Request is the raw request on the etcd transport.

type Response

type Response struct {
	ID     string
	Client string
	Data   []byte
	Error  error
}

Response is the raw response on the etcd transport.

type Result

type Result[Resp any] struct {
	Client  string
	Success Resp
	Err     error
}

Result is a result from one agent.

func SendRequests

func SendRequests[RespValue any, Resp ExactMessage[RespValue]](ctx context.Context, t *EtcdTransportServer, agents []string, msg proto.Message) ([]Result[*RespValue], error)

SendRequests allows consumers of the etcd transport to send requests to agents.

Jump to

Keyboard shortcuts

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