Documentation
¶
Index ¶
- type Client
- type Message
- type MessageHandler
- type PayloadFormat
- type PublishOption
- type PublishOptions
- type QoS
- type RetainHandling
- type SubscribeOption
- type SubscribeOptions
- type Subscription
- type UnsubscribeOption
- type UnsubscribeOptions
- type WithContentType
- type WithCorrelationData
- type WithMessageExpiry
- type WithNoLocal
- type WithPayloadFormat
- type WithQoS
- type WithResponseTopic
- type WithRetain
- type WithRetainHandling
- type WithUserProperties
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 ¶
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 ¶
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 WithPayloadFormat ¶
type WithPayloadFormat PayloadFormat
WithPayloadFormat sets the payload format indicator for the publish.
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 ¶
WithUserProperties sets the user properties for the publish or subscribe.