awsiotdev

package module
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package awsiotdev implements offline queueing and reconnecting features of MQTT protocol.

Example (DebugOut_print)
DebugPrintBackend = func(a ...interface{}) {
	fmt.Print(a...)
}

s := &debugOut{true}
s.print("Test1:", true)
s = &debugOut{false}
s.print("Test2:", false)

DebugPrintBackend = log.Print
Output:

Test1:true
Example (DebugOut_printf)
DebugPrintfBackend = func(format string, a ...interface{}) {
	fmt.Printf(format, a...)
}

s := &debugOut{true}
s.printf("Formatted value 1 (%d)", 10)
s = &debugOut{false}
s.printf("Formatted value 2 (%d)", 11)

DebugPrintfBackend = log.Printf
Output:

Formatted value 1 (10)
Example (DebugOut_println)
DebugPrintlnBackend = func(a ...interface{}) {
	fmt.Println(a...)
}

s := &debugOut{true}
s.println(errors.New("Error string 1"))
s = &debugOut{false}
s.println(errors.New("Error string 2"))

DebugPrintlnBackend = log.Println
Output:

Error string 1

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// DebugPrintBackend stores backend function of debug print output.
	// This can be replaced by custom logger.
	DebugPrintBackend func(...interface{}) = log.Print
	// DebugPrintfBackend stores backend function of debug printf output.
	// This can be replaced by custom logger.
	DebugPrintfBackend func(string, ...interface{}) = log.Printf
	// DebugPrintlnBackend stores backend function of debug println output.
	// This can be replaced by custom logger.
	DebugPrintlnBackend func(...interface{}) = log.Println
)

Functions

This section is empty.

Types

type ConnectionLostHandler

type ConnectionLostHandler func(*Options, *mqtt.ClientOptions, error)

ConnectionLostHandler is the function type for connection lost callback.

type DeviceClient

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

DeviceClient inplements mqtt.Client interface. Publishing messages and subscribing topics are queued in the DeviceClient if the network connection is lost. They are re-tried after the connection is resumed.

func New

func New(opt *Options) *DeviceClient

New returns new MQTT client with offline queueing and reconnecting. Returned client is not connected to the broaker until calling Connect().

func (*DeviceClient) AddRoute

func (s *DeviceClient) AddRoute(topic string, callback mqtt.MessageHandler)

AddRoute is not supported in this package at now.

func (*DeviceClient) Connect

func (s *DeviceClient) Connect() mqtt.Token

Connect create a connection to the broker. Returned token indicates success immediately. Subscription requests and published messages are queued until actual connection establish.

func (*DeviceClient) Disconnect

func (s *DeviceClient) Disconnect(quiesce uint)

Disconnect ends the connection to the broker. Currently, it disconnects immediately and quiesce argument is ignored.

func (*DeviceClient) IsConnected

func (s *DeviceClient) IsConnected() bool

IsConnected returns a bool whether the client is connected to the broker or not.

func (*DeviceClient) IsConnectionOpen

func (s *DeviceClient) IsConnectionOpen() bool

IsConnectionOpen returns a bool whether the client has an active connection to the broker. It is not supported in the latest paho.mqtt.golang release, but will be supported in the future release.

func (*DeviceClient) OptionsReader

func (s *DeviceClient) OptionsReader() mqtt.ClientOptionsReader

OptionsReader returns a ClientOptionsReader of the internal MQTT client.

func (*DeviceClient) Publish

func (s *DeviceClient) Publish(topic string, qos byte, retained bool, payload interface{}) mqtt.Token

Publish publishes a message. Currently, qos and retained arguments are ignored and ones specified in the options are used.

func (*DeviceClient) Subscribe

func (s *DeviceClient) Subscribe(topic string, qos byte, cb mqtt.MessageHandler) mqtt.Token

Subscribe requests a new subscription for the specified topic. Currently, qos argument is ignored and one specified in the options is used.

func (*DeviceClient) SubscribeMultiple

func (s *DeviceClient) SubscribeMultiple(filters map[string]byte, callback mqtt.MessageHandler) mqtt.Token

SubscribeMultiple requests new subscription for multiple topics. Currently, specified qos is ignored and one specified in the options is used.

func (*DeviceClient) Unsubscribe

func (s *DeviceClient) Unsubscribe(topics ...string) mqtt.Token

Unsubscribe ends the subscriptions for the specified topics.

type Options

type Options struct {
	KeyPath                  string
	CertPath                 string
	CaPath                   string
	ClientID                 string
	Region                   string
	BaseReconnectTime        time.Duration
	MaximumReconnectTime     time.Duration
	MinimumConnectionTime    time.Duration
	Keepalive                time.Duration
	URL                      string
	Debug                    bool
	Qos                      byte
	Retain                   bool
	Will                     *TopicPayload
	OfflineQueueing          bool
	OfflineQueueMaxSize      int
	OfflineQueueDropBehavior string
	AutoResubscribe          bool

	// OnConnectionLost is called if the MQTT connection is lost.
	// Pointer to the Options passed as the argument can be modified for the next reconnect.
	OnConnectionLost ConnectionLostHandler
}

Options stores configuration of the MQTT connection.

type TopicPayload

type TopicPayload struct {
	Topic   string
	Payload string
}

TopicPayload stores a pair of topic name and payload string.

Directories

Path Synopsis
Package awsiotprotocol is internal implementation of awsiotdev package.
Package awsiotprotocol is internal implementation of awsiotdev package.
Package presigner implements AWS v4 presigner wrapper for AWS IoT websocket connection.
Package presigner implements AWS v4 presigner wrapper for AWS IoT websocket connection.
Package pubqueue is internal implementation of awsiotdev package.
Package pubqueue is internal implementation of awsiotdev package.
Package subqueue is internal implementation of awsiotdev package.
Package subqueue is internal implementation of awsiotdev package.

Jump to

Keyboard shortcuts

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