client

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Request

func Request(ctx context.Context, broker string, pb *paho.Publish) (*paho.Publish, error)

Request sends a request to the given MQTT broker and waits for a response.

func RequestWithCfg

func RequestWithCfg(ctx context.Context, cc autopaho.ClientConfig, pb *paho.Publish) (*paho.Publish, error)

RequestWithCfg connects to the MQTT broker using given config. After a connection is made, it sends a request to the broker and waits for a response.

Types

type Client

type Client struct {
	sync.Once
	// contains filtered or unexported fields
}

Client provides a long connection to the MQTT broker, so that you can make continuous requests at the same time.

func New

func New(broker string) (*Client, error)

New creates a default Client with the given broker url.

func NewWithCfg

func NewWithCfg(cc autopaho.ClientConfig) (*Client, error)

NewWithCfg creates a new Client with the given client config.

func NewWithUser added in v0.1.2

func NewWithUser(broker, user, password string) (*Client, error)

NewWithUser creates a new Client with auth user and password.

func (*Client) Close

func (client *Client) Close(ctx context.Context) error

Close disconnects the Client and waits for the connection manager to exit.

func (*Client) Request

func (client *Client) Request(ctx context.Context, pb *paho.Publish) (*paho.Publish, error)

Request sends a request to the MQTT broker and waits for a response.

type Handler

type Handler struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Handler is the struct providing a request/response functionality for the paho MQTT v5 client.

func NewHandler

func NewHandler(c *autopaho.ConnectionManager, router paho.Router) *Handler

NewHandler registers a response topic and listens for responses for all requests.

func (*Handler) Close

func (h *Handler) Close(ctx context.Context) error

Close unregisters handlers of the response topic.

func (*Handler) Request

func (h *Handler) Request(ctx context.Context, pb *paho.Publish) (*paho.Publish, error)

Request sends a request to the MQTT broker and waits for a response.

func (*Handler) Subscribe added in v0.1.1

func (h *Handler) Subscribe(ctx context.Context) error

Subscribe makes a subscription to the response topic.

Jump to

Keyboard shortcuts

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