client

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PingTopic = "snapp/ping"

	DisconnectTimeout = 250
)
View Source
const (
	Namespace = "mqtt_blackbox_exporter"
	Subsystem = "client"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Client  mqtt.Client
	Logger  *zap.Logger
	Tracer  trace.Tracer
	Metrics Metrics
	Cache   *cache.Cache

	QoS         int
	Retained    bool
	IsSubscribe bool
}

Client wraps mqtt client for handling publishing and subscribing.

func New

func New(ctx context.Context,
	cfg Config,
	logger *zap.Logger,
	tracer trace.Tracer,
	cache *cache.Cache,
	isSubscribe bool,
) *Client

New creates a new mqtt client with given configuration. isSubscribe for ping message. nolint: funlen

func (*Client) Connect

func (c *Client) Connect(ctx context.Context) error

func (*Client) Disconnect

func (c *Client) Disconnect()

func (*Client) OnConnectHandler

func (c *Client) OnConnectHandler(_ mqtt.Client)

func (*Client) OnConnectionLostHandler

func (c *Client) OnConnectionLostHandler(_ mqtt.Client, err error)

func (*Client) Ping

func (c *Client) Ping(ctx context.Context, id int) error

func (*Client) Pong

func (c *Client) Pong(_ mqtt.Client, b mqtt.Message)

type Config

type Config struct {
	URL           string        `json:"url,omitempty"            koanf:"url"`
	ClientID      string        `json:"client_id,omitempty"      koanf:"clientid"`
	Username      string        `json:"username,omitempty"       koanf:"username"`
	Password      string        `json:"password,omitempty"       koanf:"password"`
	KeepAlive     time.Duration `json:"keep_alive,omitempty"     koanf:"keepalive"`
	PingTimeout   time.Duration `json:"ping_timeout,omitempty"   koanf:"ping_timeout"`
	AutoReconnect bool          `json:"auto_reconnect,omitempty" koanf:"auto_reconnect"`
	QoS           int           `json:"qo_s,omitempty"           koanf:"qos"`
	Retained      bool          `json:"retained,omitempty"       koanf:"retained"`
}

type Message

type Message struct {
	Headers map[string]string `json:"headers,omitempty"`
}

Message contains the information to send over ping.

type Metrics

type Metrics struct {
	ConnectionErrors prometheus.Counter
	PublishErrors    prometheus.Counter
	Pings            prometheus.Counter
	Pongs            prometheus.Counter
	PingDuration     prometheus.Histogram
}

Metrics has all the client metrics.

func NewMetrics

func NewMetrics() Metrics

Jump to

Keyboard shortcuts

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