rpcclient

package module
v0.0.0-...-d3c6050 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2024 License: MIT Imports: 21 Imported by: 0

README

RpcClient.go

RpcClient for Go RPC servers.

Installation

go get github.com/cgrates/rpcclient

Support

Join CGRateS on Google Groups here.

License

RpcClient.go is released under the MIT License.

Copyright (C) ITsysCOM GmbH. All Rights Reserved.

Documentation

Index

Constants

View Source
const (
	JSONrpc     = "*json"
	HTTPjson    = "*http_jsonrpc"
	GOBrpc      = "*gob"
	InternalRPC = "*internal"

	BiRPCJSON     = "*birpc_json"
	BiRPCGOB      = "*birpc_gob"
	BiRPCInternal = "*birpc_internal"
)

Constants to define the codec for RpcClient

View Source
const (
	PoolFirst              = "*first"
	PoolAsync              = "*async"
	PoolRandom             = "*random"
	PoolNext               = "*next"
	PoolFirstPositive      = "*first_positive"
	PoolFirstPositiveAsync = "*first_positive_async"
	PoolParallel           = "*parallel"
	PoolBroadcast          = "*broadcast"
	PoolBroadcastSync      = "*broadcast_sync"
	PoolBroadcastAsync     = "*broadcast_async"
)

Constants to define the strategy for RpcClientPool

Variables

View Source
var (
	ErrReqUnsynchronized       = errors.New("REQ_UNSYNCHRONIZED")
	ErrUnsupporteServiceMethod = errors.New("UNSUPPORTED_SERVICE_METHOD")
	ErrWrongArgsType           = errors.New("WRONG_ARGS_TYPE")
	ErrWrongReplyType          = errors.New("WRONG_REPLY_TYPE")
	ErrDisconnected            = errors.New("DISCONNECTED")
	ErrReplyTimeout            = errors.New("REPLY_TIMEOUT")
	ErrFailedReconnect         = errors.New("FAILED_RECONNECT")
	ErrInternallyDisconnected  = errors.New("INTERNALLY_DISCONNECTED")
	ErrUnsupportedCodec        = errors.New("UNSUPPORTED_CODEC")
	ErrSessionNotFound         = errors.New("SESSION_NOT_FOUND")
	ErrPartiallyExecuted       = errors.New("PARTIALLY_EXECUTED")
	ErrUnsupportedBiRPC        = errors.New("UNSUPPORTED_BIRPC")
)

Errors that library may return back

Functions

func IsNetworkError

func IsNetworkError(err error) bool

IsNetworkError will decide if an error is network generated or RPC one

Types

type HTTPjsonRPCClient

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

HTTPjsonRPCClient only for the rpc over http

func (*HTTPjsonRPCClient) Call

func (client *HTTPjsonRPCClient) Call(ctx *context.Context, serviceMethod string, args interface{}, reply interface{}) (err error)

Call the method needed to implement ClientConnector

type JSONrpcResponse

type JSONrpcResponse struct {
	ID     uint64
	Result *json.RawMessage
	Error  interface{}
}

JSONrpcResponse is the response received from JSON RPC

type RPCClient

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

RPCClient implements ClientConnector

func NewRPCClient

func NewRPCClient(ctx *context.Context, transport, addr string, tls bool, keyPath, certPath,
	caPath string, connectAttempts, reconnects int, maxReconnectInterval time.Duration,
	delayFunc func(time.Duration, time.Duration) func() time.Duration, connTimeout,
	replyTimeout time.Duration, codec string, internalChan chan birpc.ClientConnector,
	lazyConnect bool, biRPCClient interface{}) (rpcClient *RPCClient, err error)

NewRPCClient creates a client based on the config

func (*RPCClient) Call

func (client *RPCClient) Call(ctx *context.Context, serviceMethod string, args interface{}, reply interface{}) (err error)

Call the method needed to implement ClientConnector

type RPCCloner

type RPCCloner interface {
	RPCClone() (interface{}, error)
}

RPCCloner is an interface for objects to clone parts of themselves which are affected by concurrency at the time of RPC call

type RPCParallelClientPool

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

RPCParallelClientPool implements ClientConnector

func NewRPCParallelClientPool

func NewRPCParallelClientPool(ctx *context.Context, transport, addr string, tls bool, keyPath,
	certPath, caPath string, connectAttempts, reconnects int, maxReconnectInterval time.Duration,
	delayFunc func(time.Duration, time.Duration) func() time.Duration, connTimeout,
	replyTimeout time.Duration, codec string, internalChan chan birpc.ClientConnector, maxCounter int64,
	initConns bool, biRPCClient interface{}) (rpcClient *RPCParallelClientPool, err error)

NewRPCParallelClientPool returns a new RPCParallelClientPool

func (*RPCParallelClientPool) Call

func (pool *RPCParallelClientPool) Call(ctx *context.Context, serviceMethod string, args interface{}, reply interface{}) (err error)

Call the method needed to implement birpc.ClientConnector

type RPCPool

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

RPCPool is a pool of connections

func NewRPCPool

func NewRPCPool(transmissionType string, replyTimeout time.Duration) *RPCPool

NewRPCPool creates RPCPool

func (*RPCPool) AddClient

func (pool *RPCPool) AddClient(rcc birpc.ClientConnector)

AddClient adds a client connection in the pool

func (*RPCPool) Call

func (pool *RPCPool) Call(ctx *context.Context, serviceMethod string, args interface{}, reply interface{}) (err error)

Call the method needed to implement birpc.ClientConnector

Jump to

Keyboard shortcuts

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