mqtt

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2024 License: MIT Imports: 1 Imported by: 0

README

mqtt

import "github.com/Azure/iot-operations-sdks/go/protocol/mqtt"

Index

type Client

Client represents the underlying MQTT client utilized by the protocol library.

type Client interface {
    // Register a topic subscription with a message handler on the client.
    // Update must be called on the returned subscription to actually send
    // the subscription to the MQTT broker.
    Register(
        topic string,
        handler MessageHandler,
    ) (Subscription, error)

    // Publish sends a publish request to the MQTT broker.
    Publish(
        ctx context.Context,
        topic string,
        payload []byte,
        opts ...PublishOption,
    ) error

    // ClientID returns the identifier used by this client. If one is not
    // provided, a random ID must be generated for reconnection purposes.
    ClientID() string
}

type Message

Message represents a received message. The client implementation must support manual ack, since acks are managed by the protocol.

type Message struct {
    Topic   string
    Payload []byte
    PublishOptions
    Ack func() error
}

type MessageHandler

MessageHandler is a user-defined callback function used to handle messages received on the subscribed topic.

type MessageHandler func(context.Context, *Message) error

type PayloadFormat

type PayloadFormat byte

Payload Format indicators.

const (
    // PayloadFormat0 indicates that the payload is unspecified bytes.
    PayloadFormat0 PayloadFormat = iota

    // PayloadFormat1 indicates that the payload is UTF-8 encoded character
    // data.
    PayloadFormat1
)

type PublishOption

PublishOption represents a single publish option.

type PublishOption interface {
    // contains filtered or unexported methods
}

type PublishOptions

PublishOptions are the resolved publish options.

type PublishOptions struct {
    ContentType     string
    CorrelationData []byte
    MessageExpiry   uint32
    PayloadFormat   PayloadFormat
    QoS             QoS
    ResponseTopic   string
    Retain          bool
    UserProperties  map[string]string
}

func (*PublishOptions) Apply
func (o *PublishOptions) Apply(opts []PublishOption, rest ...PublishOption)

Apply resolves the provided list of options.

type QoS

type QoS byte

Quality of Service levels.

const (
    // QoS0 indicates at most once delivery, a.k.a. "fire and forget".
    QoS0 QoS = iota

    // QoS1 indicates at least once delivery, which ensures the message is
    // delivered at least one time to the receiver.
    QoS1

    // QoS2 indicates exactly once delivery, which ensures the message is
    // received only once by the recipient.
    QoS2
)

type RetainHandling

type RetainHandling byte

Retain Handling options.

const (
    // RetainHandling0 indicates that the Server MUST send the retained messages
    // matching the Topic Filter of the subscription to the Client.
    RetainHandling0 RetainHandling = iota

    // RetainHandling1 indicates that if the subscription did not already exist,
    // the Server MUST send all retained messages matching the Topic Filter of
    // the subscription to the Client, and if the subscription did exist the
    // Server MUST NOT send the retained messages.
    RetainHandling1

    // RetainHandling2 indicates that the Server MUST NOT send the retained
    // messages.
    RetainHandling2
)

type SubscribeOption

SubscribeOption represents a single subscribe option.

type SubscribeOption interface {
    // contains filtered or unexported methods
}

type SubscribeOptions

SubscribeOptions are the resolved subscribe options.

type SubscribeOptions struct {
    NoLocal        bool
    QoS            QoS
    Retain         bool
    RetainHandling RetainHandling
    UserProperties map[string]string
}

func (*SubscribeOptions) Apply
func (o *SubscribeOptions) Apply(opts []SubscribeOption, rest ...SubscribeOption)

Apply resolves the provided list of options.

type Subscription

Subscription represents an open subscription.

type Subscription interface {
    // Unsubscribe this subscription.
    Unsubscribe(context.Context, ...UnsubscribeOption) error

    // Update or initialize the actual underlying MQTT subscription.
    Update(context.Context, ...SubscribeOption) error
}

type UnsubscribeOption

UnsubscribeOption represents a single unsubscribe option.

type UnsubscribeOption interface {
    // contains filtered or unexported methods
}

type UnsubscribeOptions

UnsubscribeOptions are the resolve unsubscribe options.

type UnsubscribeOptions struct {
    UserProperties map[string]string
}

func (*UnsubscribeOptions) Apply
func (o *UnsubscribeOptions) Apply(opts []UnsubscribeOption, rest ...UnsubscribeOption)

Apply resolves the provided list of options.

type WithContentType

WithContentType sets the content type for the publish.

type WithContentType string

type WithCorrelationData

WithCorrelationData sets the correlation data for the publish.

type WithCorrelationData []byte

type WithMessageExpiry

WithMessageExpiry sets the message expiry interval for the publish.

type WithMessageExpiry uint32

type WithNoLocal

WithNoLocal sets the no local flag for the subscription.

type WithNoLocal bool

type WithPayloadFormat

WithPayloadFormat sets the payload format indicator for the publish.

type WithPayloadFormat PayloadFormat

type WithQoS

WithQoS sets the QoS level for the publish or subscribe.

type WithQoS QoS

type WithResponseTopic

WithResponseTopic sets the response topic for the publish.

type WithResponseTopic string

type WithRetain

WithRetain sets the retain flag for the publish or the retain-as-publish flag for the subscribe.

type WithRetain bool

type WithRetainHandling

WithRetainHandling specifies the handling of retained messages on this subscribe.

type WithRetainHandling RetainHandling

type WithUserProperties

WithUserProperties sets the user properties for the publish or subscribe.

type WithUserProperties map[string]string

Generated by gomarkdoc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// Register a topic subscription with a message handler on the client.
	// Update must be called on the returned subscription to actually send
	// the subscription to the MQTT broker.
	Register(
		topic string,
		handler MessageHandler,
	) (Subscription, error)

	// Publish sends a publish request to the MQTT broker.
	Publish(
		ctx context.Context,
		topic string,
		payload []byte,
		opts ...PublishOption,
	) error

	// ClientID returns the identifier used by this client. If one is not
	// provided, a random ID must be generated for reconnection purposes.
	ClientID() string
}

Client represents the underlying MQTT client utilized by the protocol library.

type Message

type Message struct {
	Topic   string
	Payload []byte
	PublishOptions
	Ack func() error
}

Message represents a received message. The client implementation must support manual ack, since acks are managed by the protocol.

type MessageHandler

type MessageHandler func(context.Context, *Message) error

MessageHandler is a user-defined callback function used to handle messages received on the subscribed topic.

type PayloadFormat

type PayloadFormat byte
const (
	// PayloadFormat0 indicates that the payload is unspecified bytes.
	PayloadFormat0 PayloadFormat = iota

	// PayloadFormat1 indicates that the payload is UTF-8 encoded character
	// data.
	PayloadFormat1
)

Payload Format indicators.

type PublishOption

type PublishOption interface {
	// contains filtered or unexported methods
}

PublishOption represents a single publish option.

type PublishOptions

type PublishOptions struct {
	ContentType     string
	CorrelationData []byte
	MessageExpiry   uint32
	PayloadFormat   PayloadFormat
	QoS             QoS
	ResponseTopic   string
	Retain          bool
	UserProperties  map[string]string
}

PublishOptions are the resolved publish options.

func (*PublishOptions) Apply

func (o *PublishOptions) Apply(
	opts []PublishOption,
	rest ...PublishOption,
)

Apply resolves the provided list of options.

type QoS

type QoS byte
const (
	// QoS0 indicates at most once delivery, a.k.a. "fire and forget".
	QoS0 QoS = iota

	// QoS1 indicates at least once delivery, which ensures the message is
	// delivered at least one time to the receiver.
	QoS1

	// QoS2 indicates exactly once delivery, which ensures the message is
	// received only once by the recipient.
	QoS2
)

Quality of Service levels.

type RetainHandling

type RetainHandling byte
const (
	// RetainHandling0 indicates that the Server MUST send the retained messages
	// matching the Topic Filter of the subscription to the Client.
	RetainHandling0 RetainHandling = iota

	// RetainHandling1 indicates that if the subscription did not already exist,
	// the Server MUST send all retained messages matching the Topic Filter of
	// the subscription to the Client, and if the subscription did exist the
	// Server MUST NOT send the retained messages.
	RetainHandling1

	// RetainHandling2 indicates that the Server MUST NOT send the retained
	// messages.
	RetainHandling2
)

Retain Handling options.

type SubscribeOption

type SubscribeOption interface {
	// contains filtered or unexported methods
}

SubscribeOption represents a single subscribe option.

type SubscribeOptions

type SubscribeOptions struct {
	NoLocal        bool
	QoS            QoS
	Retain         bool
	RetainHandling RetainHandling
	UserProperties map[string]string
}

SubscribeOptions are the resolved subscribe options.

func (*SubscribeOptions) Apply

func (o *SubscribeOptions) Apply(
	opts []SubscribeOption,
	rest ...SubscribeOption,
)

Apply resolves the provided list of options.

type Subscription

type Subscription interface {
	// Unsubscribe this subscription.
	Unsubscribe(context.Context, ...UnsubscribeOption) error

	// Update or initialize the actual underlying MQTT subscription.
	Update(context.Context, ...SubscribeOption) error
}

Subscription represents an open subscription.

type UnsubscribeOption

type UnsubscribeOption interface {
	// contains filtered or unexported methods
}

UnsubscribeOption represents a single unsubscribe option.

type UnsubscribeOptions

type UnsubscribeOptions struct {
	UserProperties map[string]string
}

UnsubscribeOptions are the resolve unsubscribe options.

func (*UnsubscribeOptions) Apply

func (o *UnsubscribeOptions) Apply(
	opts []UnsubscribeOption,
	rest ...UnsubscribeOption,
)

Apply resolves the provided list of options.

type WithContentType

type WithContentType string

WithContentType sets the content type for the publish.

type WithCorrelationData

type WithCorrelationData []byte

WithCorrelationData sets the correlation data for the publish.

type WithMessageExpiry

type WithMessageExpiry uint32

WithMessageExpiry sets the message expiry interval for the publish.

type WithNoLocal

type WithNoLocal bool

WithNoLocal sets the no local flag for the subscription.

type WithPayloadFormat

type WithPayloadFormat PayloadFormat

WithPayloadFormat sets the payload format indicator for the publish.

type WithQoS

type WithQoS QoS

WithQoS sets the QoS level for the publish or subscribe.

type WithResponseTopic

type WithResponseTopic string

WithResponseTopic sets the response topic for the publish.

type WithRetain

type WithRetain bool

WithRetain sets the retain flag for the publish or the retain-as-publish flag for the subscribe.

type WithRetainHandling

type WithRetainHandling RetainHandling

WithRetainHandling specifies the handling of retained messages on this subscribe.

type WithUserProperties

type WithUserProperties map[string]string

WithUserProperties sets the user properties for the publish or subscribe.

Jump to

Keyboard shortcuts

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