client

package
v0.0.0-...-cbea63e Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2021 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// NewDefaultClient is the regular Client constructor, used to create real clients.
	NewDefaultClient func() Client = newClient
	// NewClient is the default client constructor used. Override this during testing to ensure all new clients created
	// will use a mock (ensuring to set it back to DefaultClientConstructor at the conclusion of the tests).
	NewClient func() Client = NewDefaultClient
	// DefaultClient is a client with default options. This can be overridden for testing.
	DefaultClient Client = NewClient()
)

Functions

func AsyncTopic

func AsyncTopic(pub *Publication) error

AsyncTopic is a wrapper around DefaultClient.AsyncTopic

func Pub

func Pub(topic string, payload proto.Message) error

Pub is a wrapper around DefaultClient.Pub

func Push

func Push(req *Request) error

Push is a wrapper around DefaultClient.Push

func Req

func Req(req *Request, rsp proto.Message, options ...Options) errors.Error

Req is a wrapper around DefaultClient.Req

Types

type Client

type Client interface {
	// Req sends a request, and marhsals a successful response or returns an error
	Req(req *Request, rsp proto.Message, options ...Options) errors.Error

	// CustomReq is similar to Req, but without the automatic response unmarshaling, and instead returning a response
	CustomReq(req *Request, options ...Options) (*Response, errors.Error)

	// Push sends a request where we do not wish to wait for a REP (but is still REQ/REP pattern)
	Push(req *Request) error

	// AsyncTopic sends a pub/sub message (a Publication)
	AsyncTopic(pub *Publication) error

	// Pub created and sends a Publication (via AsyncTopic) in one handy step
	Pub(topic string, payload proto.Message) error
}

A client stores the details of a service client

func NewMockClient

func NewMockClient() Client

type MockClient

type MockClient struct {
	mock.Mock
	// contains filtered or unexported fields
}
var ActiveMockClient *MockClient = nil

This must be set to an instance of MockClient before tests begin. NewMockClient will always return this pointer

func (*MockClient) AddRequestExpectation

func (m *MockClient) AddRequestExpectation(req *Request, rsp proto.Message)

Adds a request expectation to the mock, to be returned when a matching request is received (only the service and endpoint parameters are compared)

func (*MockClient) AsyncTopic

func (m *MockClient) AsyncTopic(pub *Publication) error

func (*MockClient) CustomReq

func (m *MockClient) CustomReq(req *Request, options ...Options) (*Response, hailo_errors.Error)

func (*MockClient) Pub

func (m *MockClient) Pub(topic string, payload proto.Message) error

func (*MockClient) Push

func (m *MockClient) Push(req *Request) error

func (*MockClient) Req

func (m *MockClient) Req(req *Request, rsp proto.Message, options ...Options) hailo_errors.Error

type MockResponseDelivery

type MockResponseDelivery struct {
	ContentType   string
	Body          []byte
	MessageId     string
	CorrelationId string
	Headers       amqp.Table
}

type Options

type Options map[string]interface{}

Options to send with a client request

type Publication

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

Publication packages data needed to send a publication out

func NewJsonPublication

func NewJsonPublication(topic string, payload []byte) (*Publication, error)

NewJsonPublication returns a new publication based on topic and json payload

func NewPublication

func NewPublication(topic string, payload proto.Message) (*Publication, error)

NewPublication returns a new publication based on topic and payload

func (*Publication) ContentType

func (self *Publication) ContentType() string

ContentType return the content type of the publication

func (*Publication) MessageID

func (self *Publication) MessageID() string

MessageID returns the message ID of the publication

func (*Publication) Payload

func (self *Publication) Payload() []byte

Payload returns the payload of the publication

func (*Publication) SessionID

func (self *Publication) SessionID() string

SessionID returns the session ID of the publication

func (*Publication) SetSessionID

func (self *Publication) SetSessionID(id string)

SetSessionID sets the session ID of the publication

func (*Publication) Topic

func (self *Publication) Topic() string

Topic returns the topic of the publication

type Request

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

Request packages data needed to send a request out

func NewJsonRequest

func NewJsonRequest(service, endpoint string, payload []byte) (*Request, error)

NewJsonRequest builds a new request object for JSON requests

func NewProtoRequest

func NewProtoRequest(service, endpoint string, payload []byte) (*Request, error)

NewProtoRequest builds a new request object for raw protobuf requests

func NewRequest

func NewRequest(service, endpoint string, payload proto.Message) (*Request, error)

NewRequest builds a new request object, checking for bad data

func (*Request) Authorised

func (r *Request) Authorised() bool

Authorised returns whether the request has already been authorised

func (*Request) ContentType

func (r *Request) ContentType() string

ContentType returns the content type of the request

func (*Request) Endpoint

func (r *Request) Endpoint() string

Endpoint returns the endpoint of the request

func (*Request) From

func (r *Request) From() string

From returns information about which service sent this request @todo return something that can be cryptographically verified

func (*Request) FromEndpoint

func (r *Request) FromEndpoint() string

From returns information about which endpoint sent this request

func (*Request) GetOptions

func (r *Request) GetOptions() Options

func (*Request) MessageID

func (r *Request) MessageID() string

MessageID returns the message ID of the request

func (*Request) ParentMessageID

func (r *Request) ParentMessageID() string

ParentMessageID returns the message ID of a message (if any) that was received and triggered this message In other words, we use this to build up the call stack / hierarchy

func (*Request) Payload

func (r *Request) Payload() []byte

Payload returns the requests payload

func (*Request) RemoteAddr

func (r *Request) RemoteAddr() string

RemoteAddr returns the remote IP Address of the request

func (*Request) Service

func (r *Request) Service() string

Service returns the service of the request

func (*Request) SessionID

func (r *Request) SessionID() string

SessionID returns the session ID of the request

func (*Request) SetAuthorised

func (r *Request) SetAuthorised(val bool)

SetAuthorised sets whether the request has already been authorised

func (*Request) SetFrom

func (r *Request) SetFrom(service string)

SetFrom sets details about which service is making this request @todo eventually this should include an async cryptographic signature such that the receiver can verify this to establish trust

func (*Request) SetFromEndpoint

func (r *Request) SetFromEndpoint(endpoint string)

SetFromEndpoint sets details about which endpoint is making this request

func (*Request) SetOptions

func (r *Request) SetOptions(options Options)

func (*Request) SetParentMessageID

func (r *Request) SetParentMessageID(id string)

SetParentMessageID sets the parent message ID, so we can build up the call stack

func (*Request) SetRemoteAddr

func (r *Request) SetRemoteAddr(addr string)

SetRemoteAddr sets the address of the remote client making this request

func (*Request) SetSessionID

func (r *Request) SetSessionID(id string)

SetSessionID sets the session ID of the request

func (*Request) SetTraceID

func (r *Request) SetTraceID(id string)

SetTraceID sets the trace ID of the request

func (*Request) SetTraceShouldPersist

func (r *Request) SetTraceShouldPersist(val bool)

SetTraceShouldPersist sets whether the request trace should be stored persistently

func (*Request) TraceID

func (r *Request) TraceID() string

TraceID returns the trace ID of the request

func (*Request) TraceShouldPersist

func (r *Request) TraceShouldPersist() bool

TraceShouldPersist returns if the trace should be stored persistently

func (*Request) Unmarshal

func (r *Request) Unmarshal(into proto.Message) (err error)

Unmarshal the raw bytes payload of this request (into a protobuf)

type Response

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

Response wraps an AMQP delivery

func CustomReq

func CustomReq(req *Request, options ...Options) (*Response, errors.Error)

CustomReq is a wrapper around DefaultClient.CustomReq

func (*Response) Body

func (self *Response) Body() []byte

Body of the message

func (*Response) ContentType

func (self *Response) ContentType() string

ContentType returns the content type of the delivery

func (*Response) CorrelationID

func (self *Response) CorrelationID() string

CorrelationID returns the MessageId of the original message

func (*Response) Header

func (self *Response) Header() amqp.Table

Header of the message

func (*Response) IsError

func (self *Response) IsError() bool

IsError returns whether this message is an error?

func (*Response) MessageID

func (self *Response) MessageID() string

MessageID returns the ID of the underlying message transport system, which is unique per delivery, and only really useful for debugging

func (*Response) String

func (self *Response) String() string

String returns a string represenation of the response

func (*Response) Unmarshal

func (self *Response) Unmarshal(into proto.Message) (err error)

Unmarshal the raw bytes payload of this request (into a protobuf)

type Timeout

type Timeout struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Timeout stores state information about services in order to make decisions on what timeout to use when contacting other services

func NewTimeout

func NewTimeout(c Client) *Timeout

NewTimeout mints a blank timeout container from which we can calculate timeouts to use for requests

func (*Timeout) Get

func (t *Timeout) Get(service, endpoint string, attempt int) time.Duration

Get timeout to use for an attempt made calling some service our strategy is to always return a timeout immediately, and if we don't have any knowledge of what a good timeout is, pick a default and trigger a background load from the discovery service

Jump to

Keyboard shortcuts

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