conn

package
v0.0.0-beta.9-lw Latest Latest
Warning

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

Go to latest
Published: May 20, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Code taken from Matthew Titmus' book "Cloud Native Go" with minor modifications. The modifications are:

  • This code runs on the sidecar service, so that it does not have to be duplicated across all services. For that reason, the Circuit function type has been changed to take a message and return a message.

Code taken from Matthew Titmus' book "Cloud Native Go" with minor modifications. The modifications are:

  • This code runs on the sidecar service, so that it does not have to be duplicated across all services. For that reason, the Circuit function type has been changed to take a message and return a message.

Index

Constants

This section is empty.

Variables

View Source
var MsgFunc map[MessageIdTyp][]interface{}

Functions

func AddInterface

func AddInterface(msgId MessageIdTyp, i interface{})

func BlockForever

func BlockForever()

func InitGRPCconn

func InitGRPCconn(srv *Server)

func InitLogs

func InitLogs(ctx context.Context, natsConn *Conn, srv *Server)

func InitPubs

func InitPubs(natsConn *Conn, srv *Server)

func InitSubs

func InitSubs(natsConn *Conn, srv *Server)

func Initconns

func Initconns() (*Conn, *Server, error)

func NewNATSConnJS

func NewNATSConnJS(nc *nats.Conn) (nats.JetStreamContext, error)

func NewRegParams

func NewRegParams(circuitFailureThreshold uint32,
	debounceDelay string,
	retryNum uint32,
	retryDelay string) (*pb.RegistrationParams, error)

func NextMsgId

func NextMsgId() uint64

func RecvFromNATS

func RecvFromNATS(ctx context.Context, srv *Server, in *pb.Receive) (*pb.SubTopicResponse, error)

func RecvJSFromNATS

func RecvJSFromNATS(ctx context.Context, srv *Server, in *pb.ReceiveJS) (*pb.SubJSTopicResponse, error)

func SendLogsToMsgQueue

func SendLogsToMsgQueue(ctx context.Context, logs *Logs)

Types

type Circuit

type Circuit func(context.Context, *Message) (*Message, error)

func Breaker

func Breaker(circuit Circuit, failureThreshold uint) Circuit

type Conn

type Conn struct {
	Url string
	// contains filtered or unexported fields
}

func InitNATSconn

func InitNATSconn() (*Conn, error)

func NewNATSConn

func NewNATSConn(url string) (*Conn, error)

func (*Conn) Publish

func (c *Conn) Publish(t string, data []byte) error

func (*Conn) PublishJS

func (c *Conn) PublishJS(topic string, data []byte) error

func (*Conn) Subscribe

func (c *Conn) Subscribe(t string, f func(*nats.Msg)) (*nats.Subscription, error)

func (*Conn) SubscribeJS

func (c *Conn) SubscribeJS(topic string, group string) (*nats.Subscription, error)

type Effector

type Effector func(context.Context, *nats.Msg) (*nats.Msg, error)

func RetryFunc

func RetryFunc(effector Effector, retries int, delay time.Duration) Effector
type Header struct {
	ServType ServiceTyp
	ServId   ServiceIdTyp
	ReqId    RequestIdTyp
	MsgId    MessageIdTyp
}

type Logs

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

func (*Logs) ReceivedLogMsg

func (l *Logs) ReceivedLogMsg(in *pb.LogMsg) error

type Message

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

func (*Message) DebounceFirst

func (msg *Message) DebounceFirst(circuit Circuit, d time.Duration) Circuit

type MessageIdTyp

type MessageIdTyp uint32

type MsgID

type MsgID struct {
	Value uint64
	// contains filtered or unexported fields
}

GRPC creates a different goroutine to handle each request. This value is used by many goroutines. This means we have to keep it as a global, and protect it using a mutex.

type Pubs

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

func (*Pubs) Publish

func (pubs *Pubs) Publish(ctx context.Context, logger *log.Logger, in *pb.PubMsg,
	retryBehavior *pb.RetryBehavior) (*pb.PubMsgResponse, error)

func (*Pubs) Retry

func (pubs *Pubs) Retry(ctx context.Context, msg *nats.Msg) (*nats.Msg, error)

type RequestIdTyp

type RequestIdTyp uint64

type Server

type Server struct {
	pb.UnimplementedSidecarServer

	GrcpServer *grpc.Server

	Logs *Logs
	Pubs *Pubs
	Subs *Subs
	// contains filtered or unexported fields
}

func (*Server) Log

func (s *Server) Log(ctx context.Context, in *pb.LogMsg) (*emptypb.Empty, error)

func (*Server) Pub

func (s *Server) Pub(ctx context.Context, in *pb.PubMsg) (*pb.PubMsgResponse, error)

func (*Server) PubJS

func (s *Server) PubJS(ctx context.Context, in *pb.PubJSMsg) (*emptypb.Empty, error)

func (*Server) Recv

func (s *Server) Recv(ctx context.Context, in *pb.Receive) (*pb.SubTopicResponse, error)

func (*Server) RecvJS

func (s *Server) RecvJS(ctx context.Context, in *pb.ReceiveJS) (*pb.SubJSTopicResponse, error)

func (*Server) Register

func (*Server) Sub

func (s *Server) Sub(ctx context.Context, in *pb.SubMsg) (*pb.SubMsgResponse, error)

func (*Server) SubJS

func (s *Server) SubJS(ctx context.Context, in *pb.SubJSMsg) (*pb.SubJSMsgResponse, error)

func (*Server) Unsub

func (s *Server) Unsub(ctx context.Context, in *pb.UnsubMsg) (*pb.UnsubMsgResponse, error)

func (*Server) UnsubJS

func (s *Server) UnsubJS(ctx context.Context, in *pb.UnsubJSMsg) (*pb.UnsubJSMsgResponse, error)

type ServiceIdTyp

type ServiceIdTyp uint64

type ServiceTyp

type ServiceTyp uint32

type Subs

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

func (*Subs) Subscribe

func (subs *Subs) Subscribe(in *pb.SubMsg) (*pb.SubMsgResponse, error)

func (*Subs) SubscribeJS

func (subs *Subs) SubscribeJS(ctx context.Context, in *pb.SubJSMsg) (*pb.SubJSMsgResponse, error)

func (*Subs) Unsubscribe

func (subs *Subs) Unsubscribe(logger *log.Logger, in *pb.UnsubMsg) (*pb.UnsubMsgResponse, error)

func (*Subs) UnsubscribeJS

func (subs *Subs) UnsubscribeJS(logger *log.Logger, in *pb.UnsubJSMsg) (*pb.UnsubJSMsgResponse, error)

Jump to

Keyboard shortcuts

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