events

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2022 License: MIT Imports: 1 Imported by: 14

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	ID           string
	Remote       string
	Listener     string
	Username     []byte
	CleanSession bool
}

Client contains limited information about a connected client.

type Clientlike added in v1.1.2

type Clientlike interface {
	Info() Client
}

Clientlike is an interface for Clients and client-like objects that are able to describe their client/listener IDs and remote address.

type Events

type Events struct {
	OnProcessMessage // published message receieved before evaluation.
	OnMessage        // published message receieved.
	OnError          // server error.
	OnConnect        // client connected.
	OnDisconnect     // client disconnected.
	OnSubscribe      // topic subscription created.
	OnUnsubscribe    // topic subscription removed.
}

Events provides callback handlers for different event hooks.

type OnConnect added in v1.0.5

type OnConnect func(Client, Packet)

OnConnect is called when a client successfully connects to the broker.

type OnDisconnect added in v1.0.5

type OnDisconnect func(Client, error)

OnDisconnect is called when a client disconnects to the broker. An error value is passed to the function if the client disconnected abnormally, otherwise it will be nil on a normal disconnect.

type OnError added in v1.1.2

type OnError func(Client, error)

OnError is called when errors that will not be passed to OnDisconnect are handled by the server.

type OnMessage

type OnMessage func(Client, Packet) (Packet, error)

OnMessage function is called when a publish message is received. Note, this hook is ONLY called by connected client publishers, it is not triggered when using the direct s.Publish method. The function receives the sent message and the data of the client who published it, and allows the packet to be modified before it is dispatched to subscribers. If no modification is required, return the original packet data. If an error occurs, the original packet will be dispatched as if the event hook had not been triggered. This function will block message dispatching until it returns. To minimise this, have the function open a new goroutine on the embedding side.

type OnProcessMessage added in v1.2.0

type OnProcessMessage func(Client, Packet) (Packet, error)

OnProcessMessage is called when a publish message is received, allowing modification of the packet data after ACL checking has occurred but before any data is evaluated for processing - e.g. for changing the Retain flag. Note, this hook is ONLY called by connected client publishers, it is not triggered when using the direct s.Publish method. The function receives the sent message and the data of the client who published it, and allows the packet to be modified before it is dispatched to subscribers. If no modification is required, return the original packet data. If an error occurs, the original packet will be dispatched as if the event hook had not been triggered. This function will block message dispatching until it returns. To minimise this, have the function open a new goroutine on the embedding side. The `mqtt.ErrRejectPacket` error can be returned to reject and abandon any further processing of the packet.

type OnSubscribe added in v1.2.2

type OnSubscribe func(filter string, cl Client, qos byte)

OnSubscribe is called when a new subscription filter for a client is created.

type OnUnsubscribe added in v1.2.2

type OnUnsubscribe func(filter string, cl Client)

OnUnsubscribe is called when an existing subscription filter for a client is removed.

type Packet

type Packet packets.Packet

Packets is an alias for packets.Packet.

Jump to

Keyboard shortcuts

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