client

package
Version: v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2021 License: Apache-2.0 Imports: 11 Imported by: 2

Documentation

Overview

Package client is a low level client to the Choria network

It is capable of publishing any raw data contained in a choria Message to the network and supports federations, SRV records and everything else

This client has no awareness of the RPC system or anything like that, it's the lowest level raw access to the network from which higher order abstractions can be made like those that the RPC libraries require or discovery systems

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AgentFilter

func AgentFilter(f ...string) filter.Filter

AgentFilter processes a series of strings as agent filters

func ClassFilter

func ClassFilter(f ...string) filter.Filter

ClassFilter processes a series of strings as agent filters

func CombinedFilter

func CombinedFilter(f ...string) filter.Filter

CombinedFilter processes a series of strings as combined fact and class filters

func CompoundFilter

func CompoundFilter(f ...string) filter.Filter

CompoundFilter processes a series of strings as compound filters

func FactFilter

func FactFilter(f ...string) filter.Filter

FactFilter processes a series of strings as fact filters

func IdentityFilter

func IdentityFilter(f ...string) filter.Filter

IdentityFilter processes a series of strings as identity filters

func NewFilter

func NewFilter(fs ...filter.Filter) (f *protocol.Filter, err error)

NewFilter creates a new filter based on the supplied string representations

func ParseFactFilterString

func ParseFactFilterString(f string) (pf *protocol.FactFilter, err error)

ParseFactFilterString parses a fact filter string as typically typed on the CLI

Types

type ChoriaFramework

type ChoriaFramework interface {
	Configuration() *config.Config
	Logger(string) *logrus.Entry
	NewRequestID() (string, error)
	Certname() string
	MiddlewareServers() (srvcache.Servers, error)
	NewConnector(ctx context.Context, servers func() (srvcache.Servers, error), name string, logger *logrus.Entry) (conn choria.Connector, err error)
	NewMessage(payload string, agent string, collective string, msgType string, request *choria.Message) (msg *choria.Message, err error)
	NewTransportFromJSON(data string) (message protocol.TransportMessage, err error)
}

type Client

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

Client is a basic low level high performance Choria client

func New

func New(fw ChoriaFramework, opts ...Option) (*Client, error)

New creates a Choria client

func (*Client) Request

func (c *Client) Request(ctx context.Context, msg *choria.Message, handler Handler) (err error)

Request performs a request

handler will be called for every reply that gets received, when handler is nil this means no receiving listeners, workers or subscriptions are setup effectively the message is published and forgotten

This fire and forget approach is useful when one do not care for the replies or when the reply to target in the message is set to a custom reply target meaning the client will anyway never receive the replies

type Connector

type Connector interface {
	QueueSubscribe(ctx context.Context, name string, subject string, group string, output chan *choria.ConnectorMessage) error
	Publish(msg *choria.Message) error
}

Connector is a connection to the choria network

type Handler

type Handler func(ctx context.Context, m *choria.ConnectorMessage)

Handler handles individual messages

type Option

type Option func(c *Client)

Option configures the broadcast discovery method

func Connection

func Connection(conn Connector) Option

Connection Supplies a custom connection, when this is supplied this is the only connection that will be used for the duration of this client for all publishes and replies

This might have severe performance impact and might even cause message loss, my suggestion would be to use this only when doing batch style messages where you expect small amounts of replies

func Log

func Log(l *logrus.Entry) Option

Log sets a specific logrus logger else a new one is made

func Name

func Name(n string) Option

Name sets a NATS connection name to use, without this random names will be made.

This setting is important if you make a daemon that makes many long client connections as each client connection makes Prometheus stats based on the name and you'll be leaking many stats over time

func OnPublishFinish

func OnPublishFinish(f func()) Option

OnPublishFinish function to call synchronously when publishing ends

func OnPublishStart

func OnPublishStart(f func()) Option

OnPublishStart function to call synchronously when publishing starts

func Receivers

func Receivers(r int) Option

Receivers sets how many receiver connections should be started

func Timeout

func Timeout(t time.Duration) Option

Timeout sets the request timeout

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL