<!-- Code generated by gomarkdoc. DO NOT EDIT -->

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

## Index

- [Constants](<#constants>)
- [func IsTopicFilterMatch\(topicFilter, topicName string\) bool](<#IsTopicFilterMatch>)
- [func RandomClientID\(\) string](<#RandomClientID>)
- [type AIOBrokerFeatureError](<#AIOBrokerFeatureError>)
  - [func \(e \*AIOBrokerFeatureError\) Error\(\) string](<#AIOBrokerFeatureError.Error>)
- [type Ack](<#Ack>)
- [type ClientState](<#ClientState>)
- [type ClientStateError](<#ClientStateError>)
  - [func \(e \*ClientStateError\) Error\(\) string](<#ClientStateError.Error>)
- [type ConnackError](<#ConnackError>)
  - [func \(e \*ConnackError\) Error\(\) string](<#ConnackError.Error>)
- [type ConnectEvent](<#ConnectEvent>)
- [type ConnectEventHandler](<#ConnectEventHandler>)
- [type ConnectionError](<#ConnectionError>)
  - [func \(e \*ConnectionError\) Error\(\) string](<#ConnectionError.Error>)
  - [func \(e \*ConnectionError\) Unwrap\(\) error](<#ConnectionError.Unwrap>)
- [type ConnectionProvider](<#ConnectionProvider>)
  - [func TCPConnection\(hostname string, port uint16\) ConnectionProvider](<#TCPConnection>)
  - [func TLSConnection\(hostname string, port uint16, opts ...TLSOption\) ConnectionProvider](<#TLSConnection>)
- [type DisconnectError](<#DisconnectError>)
  - [func \(e \*DisconnectError\) Error\(\) string](<#DisconnectError.Error>)
- [type DisconnectEvent](<#DisconnectEvent>)
- [type DisconnectEventHandler](<#DisconnectEventHandler>)
- [type Env](<#Env>)
  - [func SessionClientConfigFromEnv\(\) \(\*Env, error\)](<#SessionClientConfigFromEnv>)
- [type FatalConnackError](<#FatalConnackError>)
  - [func \(e \*FatalConnackError\) Error\(\) string](<#FatalConnackError.Error>)
- [type FatalDisconnectError](<#FatalDisconnectError>)
  - [func \(e \*FatalDisconnectError\) Error\(\) string](<#FatalDisconnectError.Error>)
- [type HandlerPanicError](<#HandlerPanicError>)
  - [func \(e \*HandlerPanicError\) Error\(\) string](<#HandlerPanicError.Error>)
- [type InvalidArgumentError](<#InvalidArgumentError>)
  - [func \(e \*InvalidArgumentError\) Error\(\) string](<#InvalidArgumentError.Error>)
  - [func \(e \*InvalidArgumentError\) Unwrap\(\) error](<#InvalidArgumentError.Unwrap>)
- [type Message](<#Message>)
- [type MessageHandler](<#MessageHandler>)
- [type PasswordProvider](<#PasswordProvider>)
  - [func ConstantPassword\(password \[\]byte\) PasswordProvider](<#ConstantPassword>)
  - [func FilePassword\(filename string\) PasswordProvider](<#FilePassword>)
- [type PublishOption](<#PublishOption>)
  - [func WithPersist\(\) PublishOption](<#WithPersist>)
- [type PublishOptions](<#PublishOptions>)
- [type PublishQueueFullError](<#PublishQueueFullError>)
  - [func \(\*PublishQueueFullError\) Error\(\) string](<#PublishQueueFullError.Error>)
- [type SessionClient](<#SessionClient>)
  - [func NewSessionClient\(clientID string, connectionProvider ConnectionProvider, opts ...SessionClientOption\) \(\*SessionClient, error\)](<#NewSessionClient>)
  - [func NewSessionClientFromEnv\(opt ...SessionClientOption\) \(\*SessionClient, error\)](<#NewSessionClientFromEnv>)
  - [func \(c \*SessionClient\) ID\(\) string](<#SessionClient.ID>)
  - [func \(c \*SessionClient\) Publish\(ctx context.Context, topic string, payload \[\]byte, opts ...PublishOption\) \(\*Ack, error\)](<#SessionClient.Publish>)
  - [func \(c \*SessionClient\) RegisterConnectEventHandler\(handler ConnectEventHandler\) func\(\)](<#SessionClient.RegisterConnectEventHandler>)
  - [func \(c \*SessionClient\) RegisterDisconnectEventHandler\(handler DisconnectEventHandler\) func\(\)](<#SessionClient.RegisterDisconnectEventHandler>)
  - [func \(c \*SessionClient\) RegisterFatalErrorHandler\(handler func\(error\)\) func\(\)](<#SessionClient.RegisterFatalErrorHandler>)
  - [func \(c \*SessionClient\) RegisterMessageHandler\(handler MessageHandler\) func\(\)](<#SessionClient.RegisterMessageHandler>)
  - [func \(c \*SessionClient\) Start\(\) error](<#SessionClient.Start>)
  - [func \(c \*SessionClient\) Stop\(\) error](<#SessionClient.Stop>)
  - [func \(c \*SessionClient\) Subscribe\(ctx context.Context, topic string, opts ...SubscribeOption\) \(\*Ack, error\)](<#SessionClient.Subscribe>)
  - [func \(c \*SessionClient\) Unsubscribe\(ctx context.Context, topic string, opts ...UnsubscribeOption\) \(\*Ack, error\)](<#SessionClient.Unsubscribe>)
- [type SessionClientOption](<#SessionClientOption>)
  - [func WithAuth\(provider auth.Provider\) SessionClientOption](<#WithAuth>)
  - [func WithConnectPersist\(\) SessionClientOption](<#WithConnectPersist>)
  - [func WithConnectionRetry\(policy retry.Policy\) SessionClientOption](<#WithConnectionRetry>)
  - [func WithLogger\(log \*slog.Logger\) SessionClientOption](<#WithLogger>)
- [type SessionClientOptions](<#SessionClientOptions>)
  - [func \(o \*SessionClientOptions\) Apply\(opts \[\]SessionClientOption, rest ...SessionClientOption\)](<#SessionClientOptions.Apply>)
- [type SessionLostError](<#SessionLostError>)
  - [func \(\*SessionLostError\) Error\(\) string](<#SessionLostError.Error>)
- [type SubscribeOption](<#SubscribeOption>)
- [type SubscribeOptions](<#SubscribeOptions>)
- [type TLSOption](<#TLSOption>)
  - [func WithCA\(caFile string\) TLSOption](<#WithCA>)
  - [func WithEncryptedX509\(certFile, keyFile, passFile string\) TLSOption](<#WithEncryptedX509>)
  - [func WithX509\(certFile, keyFile string\) TLSOption](<#WithX509>)
- [type UnsubscribeOption](<#UnsubscribeOption>)
- [type UnsubscribeOptions](<#UnsubscribeOptions>)
- [type UsernameProvider](<#UsernameProvider>)
  - [func ConstantUsername\(username string\) UsernameProvider](<#ConstantUsername>)
- [type WithCleanStart](<#WithCleanStart>)
- [type WithConnectUserProperties](<#WithConnectUserProperties>)
- [type WithConnectionTimeout](<#WithConnectionTimeout>)
- [type WithContentType](<#WithContentType>)
- [type WithCorrelationData](<#WithCorrelationData>)
- [type WithDisableAIOBrokerFeatures](<#WithDisableAIOBrokerFeatures>)
- [type WithKeepAlive](<#WithKeepAlive>)
- [type WithMessageExpiry](<#WithMessageExpiry>)
- [type WithNoLocal](<#WithNoLocal>)
- [type WithPassword](<#WithPassword>)
- [type WithPayloadFormat](<#WithPayloadFormat>)
- [type WithQoS](<#WithQoS>)
- [type WithReceiveMaximum](<#WithReceiveMaximum>)
- [type WithResponseTopic](<#WithResponseTopic>)
- [type WithRetain](<#WithRetain>)
- [type WithRetainHandling](<#WithRetainHandling>)
- [type WithSessionExpiry](<#WithSessionExpiry>)
- [type WithUserProperties](<#WithUserProperties>)
- [type WithUsername](<#WithUsername>)


## Constants

<a name="AIOPersistence"></a>AIOPersistence is the user\-property used to indicate to the AIO broker that it should persist messages to disk.

```go
const AIOPersistence = "aio-persistence"
```

<a name="IsTopicFilterMatch"></a>
## func [IsTopicFilterMatch](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/topic_filter.go#L10>)

```go
func IsTopicFilterMatch(topicFilter, topicName string) bool
```

IsTopicFilterMatch checks if a topic name matches a topic filter.

<a name="RandomClientID"></a>
## func [RandomClientID](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/random_client_id.go#L23>)

```go
func RandomClientID() string
```

RandomClientID generates a random valid MQTT client ID. This should never be used in production \(as it fully invalidates all session guarantees\) but can be useful in testing to prevent parallel tests from conflicting.

<a name="AIOBrokerFeatureError"></a>
## type [AIOBrokerFeatureError](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/errors.go#L159-L161>)

AIOBrokerFeatureError indicates that a feature specific to the AIO Broker was used when AIO Broker features were explicitly disabled.

```go
type AIOBrokerFeatureError struct {
    // contains filtered or unexported fields
}
```

<a name="AIOBrokerFeatureError.Error"></a>
### func \(\*AIOBrokerFeatureError\) [Error](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/errors.go#L163>)

```go
func (e *AIOBrokerFeatureError) Error() string
```



<a name="Ack"></a>
## type [Ack](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/alias.go#L30>)

Ack contains values from PUBACK/SUBACK/UNSUBACK packets received from the MQTT server.

```go
type Ack = mqtt.Ack
```

<a name="ClientState"></a>
## type [ClientState](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/errors.go#L8>)

ClientState indicates the current state of the session client.

```go
type ClientState byte
```

<a name="NotStarted"></a>

```go
const (
    // The session client has not yet been started.
    NotStarted ClientState = iota

    // The session client has been started and has not yet been stopped by the
    // user or terminated due to a fatal error.
    Started

    // The session client has been stopped by the user or terminated due to a
    // fatal error.
    ShutDown
)
```

<a name="ClientStateError"></a>
## type [ClientStateError](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/errors.go#L25-L27>)

ClientStateError is returned when the operation cannot proceed due to the state of the session client.

```go
type ClientStateError struct {
    State ClientState
}
```

<a name="ClientStateError.Error"></a>
### func \(\*ClientStateError\) [Error](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/errors.go#L29>)

```go
func (e *ClientStateError) Error() string
```



<a name="ConnackError"></a>
## type [ConnackError](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/errors.go#L103-L105>)

ConnackError indicates that the session client received a CONNACK with a reason code that indicates an error but is not deemed to be fatal. It may appear as a fatal error if it is the final error returned once the session client has exhausted its connection retries.

```go
type ConnackError struct {
    ReasonCode byte
}
```

<a name="ConnackError.Error"></a>
### func \(\*ConnackError\) [Error](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/errors.go#L107>)

```go
func (e *ConnackError) Error() string
```



<a name="ConnectEvent"></a>
## type [ConnectEvent](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/alias.go#L18>)

ConnectEvent contains the relevent metadata provided to the handler when the MQTT client connects to the broker.

```go
type ConnectEvent = mqtt.ConnectEvent
```

<a name="ConnectEventHandler"></a>
## type [ConnectEventHandler](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/alias.go#L21>)

ConnectEventHandler is a user\-defined callback function used to respond to connection notifications from the MQTT client.

```go
type ConnectEventHandler = mqtt.ConnectEventHandler
```

<a name="ConnectionError"></a>
## type [ConnectionError](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/errors.go#L83-L86>)

ConnectionError indicates that the session client has terminated due to an issue opening the network connection to the MQTT server. It may wrap an underlying error using Go standard error wrapping.

```go
type ConnectionError struct {
    // contains filtered or unexported fields
}
```

<a name="ConnectionError.Error"></a>
### func \(\*ConnectionError\) [Error](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/errors.go#L88>)

```go
func (e *ConnectionError) Error() string
```



<a name="ConnectionError.Unwrap"></a>
### func \(\*ConnectionError\) [Unwrap](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/errors.go#L95>)

```go
func (e *ConnectionError) Unwrap() error
```



<a name="ConnectionProvider"></a>
## type [ConnectionProvider](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/net.go#L18>)

ConnectionProvider is a function that returns a net.Conn connected to an MQTT server that is ready to read to and write from. Note that the returned net.Conn must be thread\-safe \(i.e., concurrent Write calls must not interleave\).

```go
type ConnectionProvider func(context.Context) (net.Conn, error)
```

<a name="TCPConnection"></a>
### func [TCPConnection](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/net.go#L22>)

```go
func TCPConnection(hostname string, port uint16) ConnectionProvider
```

TCPConnection is a connection provider that connects to an MQTT server over TCP.

<a name="TLSConnection"></a>
### func [TLSConnection](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/net.go#L87-L91>)

```go
func TLSConnection(hostname string, port uint16, opts ...TLSOption) ConnectionProvider
```

TLSConnection is a connection provider that connects to an MQTT server with TLS over TCP.

<a name="DisconnectError"></a>
## type [DisconnectError](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/errors.go#L47-L49>)

DisconnectError indicates that the session client received a DISCONNECT packet from the server with a reason code that is not deemed to be fatal. It is primarily used for internal tracking and should not be expected by users except in rare cases in logs.

```go
type DisconnectError struct {
    ReasonCode byte
}
```

<a name="DisconnectError.Error"></a>
### func \(\*DisconnectError\) [Error](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/errors.go#L51>)

```go
func (e *DisconnectError) Error() string
```



<a name="DisconnectEvent"></a>
## type [DisconnectEvent](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/alias.go#L24>)

DisconnectEvent contains the relevent metadata provided to the handler when the MQTT client disconnects from the broker.

```go
type DisconnectEvent = mqtt.DisconnectEvent
```

<a name="DisconnectEventHandler"></a>
## type [DisconnectEventHandler](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/alias.go#L27>)

DisconnectEventHandler is a user\-defined callback function used to respond to disconnection notifications from the MQTT client.

```go
type DisconnectEventHandler = mqtt.DisconnectEventHandler
```

<a name="Env"></a>
## type [Env](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/env.go#L18-L22>)

Env provides all session client parameters parsed from well\-known environment variables.

```go
type Env struct {
    ClientID           string
    ConnectionProvider ConnectionProvider
    *SessionClientOptions
}
```

<a name="SessionClientConfigFromEnv"></a>
### func [SessionClientConfigFromEnv](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/env.go#L40>)

```go
func SessionClientConfigFromEnv() (*Env, error)
```

SessionClientConfigFromEnv parses a session client configuration from well\-known environment variables. Note that this will only return an error if the environment variables parse incorrectly; it will not return an error if required parameters \(e.g. for the connection provider\) are missing, to allow optional parameters to be specified from environment independently.

<a name="FatalConnackError"></a>
## type [FatalConnackError](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/errors.go#L116-L118>)

FatalConnackError indicates that the session client has terminated due to receiving a CONNACK with with a reason code that is deemed to be fatal.

```go
type FatalConnackError struct {
    ReasonCode byte
}
```

<a name="FatalConnackError.Error"></a>
### func \(\*FatalConnackError\) [Error](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/errors.go#L120>)

```go
func (e *FatalConnackError) Error() string
```



<a name="FatalDisconnectError"></a>
## type [FatalDisconnectError](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/errors.go#L61-L63>)

FatalDisconnectError indicates that the session client has terminated due to receiving a DISCONNECT packet from the server with a reason code that is deemed to be fatal.

```go
type FatalDisconnectError struct {
    ReasonCode byte
}
```

<a name="FatalDisconnectError.Error"></a>
### func \(\*FatalDisconnectError\) [Error](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/errors.go#L65>)

```go
func (e *FatalDisconnectError) Error() string
```



<a name="HandlerPanicError"></a>
## type [HandlerPanicError](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/errors.go#L172-L174>)

HandlerPanicError indicates that a user\-provided handler panicked. This error will never be returned, only logged.

```go
type HandlerPanicError struct {
    // contains filtered or unexported fields
}
```

<a name="HandlerPanicError.Error"></a>
### func \(\*HandlerPanicError\) [Error](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/errors.go#L176>)

```go
func (e *HandlerPanicError) Error() string
```



<a name="InvalidArgumentError"></a>
## type [InvalidArgumentError](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/errors.go#L130-L133>)

InvalidArgumentError indicates that the user has provided an invalid value for an option. It may wrap an underlying error using Go standard error wrapping.

```go
type InvalidArgumentError struct {
    // contains filtered or unexported fields
}
```

<a name="InvalidArgumentError.Error"></a>
### func \(\*InvalidArgumentError\) [Error](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/errors.go#L135>)

```go
func (e *InvalidArgumentError) Error() string
```



<a name="InvalidArgumentError.Unwrap"></a>
### func \(\*InvalidArgumentError\) [Unwrap](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/errors.go#L142>)

```go
func (e *InvalidArgumentError) Unwrap() error
```



<a name="Message"></a>
## type [Message](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/alias.go#L12>)

Message represents a received message.

```go
type Message = mqtt.Message
```

<a name="MessageHandler"></a>
## type [MessageHandler](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/alias.go#L15>)

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

```go
type MessageHandler = mqtt.MessageHandler
```

<a name="PasswordProvider"></a>
## type [PasswordProvider](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/username_password.go#L19>)

PasswordProvider is a function that returns an MQTT password and flag. Note that if the returned flag is false, the returned password is ignored.

```go
type PasswordProvider func(context.Context) ([]byte, bool, error)
```

<a name="ConstantPassword"></a>
### func [ConstantPassword](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/username_password.go#L34>)

```go
func ConstantPassword(password []byte) PasswordProvider
```

ConstantPassword is a PasswordProvider implementation that returns an unchanging password. This can be used if the password does not need to be updated between MQTT connections.

<a name="FilePassword"></a>
### func [FilePassword](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/username_password.go#L42>)

```go
func FilePassword(filename string) PasswordProvider
```

FilePassword is a PasswordProvider implementation that reads a password from a given filename for each MQTT connection.

<a name="PublishOption"></a>
## type [PublishOption](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/alias.go#L43>)

PublishOption represents a single publish option.

```go
type PublishOption = mqtt.PublishOption
```

<a name="WithPersist"></a>
### func [WithPersist](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/features.go#L17>)

```go
func WithPersist() PublishOption
```

WithPersist is a convenience option to set the AIO persistence flag on a PUBLISH request.

<a name="PublishOptions"></a>
## type [PublishOptions](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/alias.go#L41>)

PublishOptions are the resolved publish options.

```go
type PublishOptions = mqtt.PublishOptions
```

<a name="PublishQueueFullError"></a>
## type [PublishQueueFullError](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/errors.go#L151>)

PublishQueueFullError is returned if there are too many publishes enqueued and the session client is not accepting any more. This should very rarely occur, and if it does, it is a sign that either the connection is unstable or the application is sending messages at a faster rate than can be handled by the session client or server.

```go
type PublishQueueFullError struct{}
```

<a name="PublishQueueFullError.Error"></a>
### func \(\*PublishQueueFullError\) [Error](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/errors.go#L153>)

```go
func (*PublishQueueFullError) Error() string
```



<a name="SessionClient"></a>
## type [SessionClient](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/session_client.go#L20-L58>)

SessionClient implements an MQTT session client supporting MQTT v5 with QoS 0 and QoS 1 support.

```go
type SessionClient struct {
    // contains filtered or unexported fields
}
```

<a name="NewSessionClient"></a>
### func [NewSessionClient](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/session_client.go#L62-L66>)

```go
func NewSessionClient(clientID string, connectionProvider ConnectionProvider, opts ...SessionClientOption) (*SessionClient, error)
```

NewSessionClient constructs a new session client with user options.

<a name="NewSessionClientFromEnv"></a>
### func [NewSessionClientFromEnv](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/env.go#L145-L147>)

```go
func NewSessionClientFromEnv(opt ...SessionClientOption) (*SessionClient, error)
```

NewSessionClientFromEnv is a shorthand for constructing a session client using SessionClientConfigFromEnv.

<a name="SessionClient.ID"></a>
### func \(\*SessionClient\) [ID](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/session_client.go#L125>)

```go
func (c *SessionClient) ID() string
```

ID returns the MQTT client ID for this session client.

<a name="SessionClient.Publish"></a>
### func \(\*SessionClient\) [Publish](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/publish.go#L114-L119>)

```go
func (c *SessionClient) Publish(ctx context.Context, topic string, payload []byte, opts ...PublishOption) (*Ack, error)
```

Publish a MQTT message on the given topic.

<a name="SessionClient.RegisterConnectEventHandler"></a>
### func \(\*SessionClient\) [RegisterConnectEventHandler](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/connect.go#L20-L22>)

```go
func (c *SessionClient) RegisterConnectEventHandler(handler ConnectEventHandler) func()
```

RegisterConnectEventHandler registers a handler to a list of handlers that are called synchronously in registration order whenever the session client successfully establishes an MQTT connection. Note that since the handler gets called synchronously, handlers should not block for an extended period of time to avoid blocking the session client.

<a name="SessionClient.RegisterDisconnectEventHandler"></a>
### func \(\*SessionClient\) [RegisterDisconnectEventHandler](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/connect.go#L38-L40>)

```go
func (c *SessionClient) RegisterDisconnectEventHandler(handler DisconnectEventHandler) func()
```

RegisterDisconnectEventHandler registers a handler to a list of handlers that are called synchronously in registration order whenever the session client detects a disconnection from the MQTT server. Note that since the handler gets called synchronously, handlers should not block for an extended period of time to avoid blocking the session client.

<a name="SessionClient.RegisterFatalErrorHandler"></a>
### func \(\*SessionClient\) [RegisterFatalErrorHandler](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/connect.go#L53-L55>)

```go
func (c *SessionClient) RegisterFatalErrorHandler(handler func(error)) func()
```

RegisterFatalErrorHandler registers a handler that is called in a goroutine if the session client terminates due to a fatal error.

<a name="SessionClient.RegisterMessageHandler"></a>
### func \(\*SessionClient\) [RegisterMessageHandler](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/subscribe.go#L63>)

```go
func (c *SessionClient) RegisterMessageHandler(handler MessageHandler) func()
```

RegisterMessageHandler registers a message handler on this client. Returns a callback to remove the message handler.

<a name="SessionClient.Start"></a>
### func \(\*SessionClient\) [Start](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/connect.go#L69>)

```go
func (c *SessionClient) Start() error
```

Start the session client, spawning any necessary background goroutines. In order to terminate the session client and clean up any running goroutines, Stop\(\) must be called after calling Start\(\).

<a name="SessionClient.Stop"></a>
### func \(\*SessionClient\) [Stop](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/connect.go#L94>)

```go
func (c *SessionClient) Stop() error
```

Stop the session client, terminating any pending operations and cleaning up background goroutines.

<a name="SessionClient.Subscribe"></a>
### func \(\*SessionClient\) [Subscribe](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/subscribe.go#L80-L84>)

```go
func (c *SessionClient) Subscribe(ctx context.Context, topic string, opts ...SubscribeOption) (*Ack, error)
```

Subscribe to the given topic.

<a name="SessionClient.Unsubscribe"></a>
### func \(\*SessionClient\) [Unsubscribe](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/subscribe.go#L123-L127>)

```go
func (c *SessionClient) Unsubscribe(ctx context.Context, topic string, opts ...UnsubscribeOption) (*Ack, error)
```

Unsubscribe from the given topic.

<a name="SessionClientOption"></a>
## type [SessionClientOption](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/session_client_options.go#L17>)

SessionClientOption represents a single option for the session client.

```go
type SessionClientOption interface {
    // contains filtered or unexported methods
}
```

<a name="WithAuth"></a>
### func [WithAuth](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/session_client_options.go#L144>)

```go
func WithAuth(provider auth.Provider) SessionClientOption
```

WithAuth sets the enhanced authentication provider for the session client.

<a name="WithConnectPersist"></a>
### func [WithConnectPersist](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/features.go#L11>)

```go
func WithConnectPersist() SessionClientOption
```

WithConnectPersist is a convenience option to set the AIO persistence flag on the CONNECT request.

<a name="WithConnectionRetry"></a>
### func [WithConnectionRetry](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/session_client_options.go#L135>)

```go
func WithConnectionRetry(policy retry.Policy) SessionClientOption
```

WithConnectionRetry sets the connection retry policy for the session client.

<a name="WithLogger"></a>
### func [WithLogger](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/session_client_options.go#L153>)

```go
func WithLogger(log *slog.Logger) SessionClientOption
```

WithLogger sets the logger for the session client.

<a name="SessionClientOptions"></a>
## type [SessionClientOptions](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/session_client_options.go#L20-L36>)

SessionClientOptions are the resolved options for the session client.

```go
type SessionClientOptions struct {
    CleanStart               bool
    KeepAlive                uint16
    SessionExpiry            uint32
    ReceiveMaximum           uint16
    ConnectUserProperties    map[string]string
    DisableAIOBrokerFeatures bool

    ConnectionRetry   retry.Policy
    ConnectionTimeout time.Duration

    Username UsernameProvider
    Password PasswordProvider
    Auth     auth.Provider

    Logger *slog.Logger
}
```

<a name="SessionClientOptions.Apply"></a>
### func \(\*SessionClientOptions\) [Apply](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/session_client_options.go#L80-L83>)

```go
func (o *SessionClientOptions) Apply(opts []SessionClientOption, rest ...SessionClientOption)
```

Apply resolves the provided list of options.

<a name="SessionLostError"></a>
## type [SessionLostError](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/errors.go#L74>)

SessionLostError indicates that the session client has terminated due to receiving a CONNACK with session present false when reconnecting.

```go
type SessionLostError struct{}
```

<a name="SessionLostError.Error"></a>
### func \(\*SessionLostError\) [Error](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/errors.go#L76>)

```go
func (*SessionLostError) Error() string
```



<a name="SubscribeOption"></a>
## type [SubscribeOption](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/alias.go#L35>)

SubscribeOption represents a single subscribe option.

```go
type SubscribeOption = mqtt.SubscribeOption
```

<a name="SubscribeOptions"></a>
## type [SubscribeOptions](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/alias.go#L33>)

SubscribeOptions are the resolved subscribe options.

```go
type SubscribeOptions = mqtt.SubscribeOptions
```

<a name="TLSOption"></a>
## type [TLSOption](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/net.go#L45>)

TLSOption is a function that modifies a tls.Config to be used when opening a TLS connection to an MQTT server. More than one can be provided to TLSConnection; they will be executed in order, with the first passed the empty \(default\) TLS config. See tls.Config for more information on TLS configuration options.

```go
type TLSOption func(context.Context, *tls.Config) error
```

<a name="WithCA"></a>
### func [WithCA](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/net.go#L74>)

```go
func WithCA(caFile string) TLSOption
```

WithCA loads a CA certificate pool into the root CAs of the TLS configuration.

<a name="WithEncryptedX509"></a>
### func [WithEncryptedX509](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/net.go#L61>)

```go
func WithEncryptedX509(certFile, keyFile, passFile string) TLSOption
```

WithEncryptedX509 appends an X509 certificate to the TLS certificates, using a password file to decrypt the certificate key.

<a name="WithX509"></a>
### func [WithX509](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/net.go#L48>)

```go
func WithX509(certFile, keyFile string) TLSOption
```

WithX509 appends an X509 certificate to the TLS certificates.

<a name="UnsubscribeOption"></a>
## type [UnsubscribeOption](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/alias.go#L39>)

UnsubscribeOption represents a single unsubscribe option.

```go
type UnsubscribeOption = mqtt.UnsubscribeOption
```

<a name="UnsubscribeOptions"></a>
## type [UnsubscribeOptions](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/alias.go#L37>)

UnsubscribeOptions are the resolve unsubscribe options.

```go
type UnsubscribeOptions = mqtt.UnsubscribeOptions
```

<a name="UsernameProvider"></a>
## type [UsernameProvider](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/username_password.go#L14>)

UsernameProvider is a function that returns an MQTT username and flag. Note that if the returned flag is false, the returned username is ignored.

```go
type UsernameProvider func(context.Context) (string, bool, error)
```

<a name="ConstantUsername"></a>
### func [ConstantUsername](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/username_password.go#L25>)

```go
func ConstantUsername(username string) UsernameProvider
```

ConstantUsername is a UsernameProvider implementation that returns an unchanging username. This can be used if the username does not need to be updated between MQTT connections.

<a name="WithCleanStart"></a>
## type [WithCleanStart](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/session_client_options.go#L46>)

WithCleanStart sets whether the initial connection will be made without retaining any existing session state. This is by definition set to false for any reconnections.

```go
type WithCleanStart bool
```

<a name="WithConnectUserProperties"></a>
## type [WithConnectUserProperties](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/session_client_options.go#L59>)

WithConnectUserProperties sets the user properties for the CONNECT packet.

```go
type WithConnectUserProperties map[string]string
```

<a name="WithConnectionTimeout"></a>
## type [WithConnectionTimeout](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/session_client_options.go#L41>)

WithConnectionTimeout sets the connection timeout for a single connection attempt. If a timeout is desired for the entire connection process, it should be specified via the connection retry policy.

```go
type WithConnectionTimeout time.Duration
```

<a name="WithContentType"></a>
## type [WithContentType](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/alias.go#L46>)

WithContentType sets the content type for the publish.

```go
type WithContentType = mqtt.WithContentType
```

<a name="WithCorrelationData"></a>
## type [WithCorrelationData](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/alias.go#L48>)

WithCorrelationData sets the correlation data for the publish.

```go
type WithCorrelationData = mqtt.WithCorrelationData
```

<a name="WithDisableAIOBrokerFeatures"></a>
## type [WithDisableAIOBrokerFeatures](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/session_client_options.go#L64>)

WithDisableAIOBrokerFeatures disables behavior specific to the AIO Broker. Only use this option if you are using another broker and encounter failures.

```go
type WithDisableAIOBrokerFeatures bool
```

<a name="WithKeepAlive"></a>
## type [WithKeepAlive](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/session_client_options.go#L49>)

WithKeepAlive sets the keep\-alive interval \(in seconds\).

```go
type WithKeepAlive uint16
```

<a name="WithMessageExpiry"></a>
## type [WithMessageExpiry](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/alias.go#L50>)

WithMessageExpiry sets the message expiry interval for the publish.

```go
type WithMessageExpiry = mqtt.WithMessageExpiry
```

<a name="WithNoLocal"></a>
## type [WithNoLocal](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/alias.go#L52>)

WithNoLocal sets the no local flag for the subscription.

```go
type WithNoLocal = mqtt.WithNoLocal
```

<a name="WithPassword"></a>
## type [WithPassword](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/session_client_options.go#L72>)

WithPassword sets the PasswordProvider that the session client uses to get the password for each connection.

```go
type WithPassword PasswordProvider
```

<a name="WithPayloadFormat"></a>
## type [WithPayloadFormat](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/alias.go#L54>)

WithPayloadFormat sets the payload format indicator for the publish.

```go
type WithPayloadFormat = mqtt.WithPayloadFormat
```

<a name="WithQoS"></a>
## type [WithQoS](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/alias.go#L56>)

WithQoS sets the QoS level for the publish or subscribe.

```go
type WithQoS = mqtt.WithQoS
```

<a name="WithReceiveMaximum"></a>
## type [WithReceiveMaximum](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/session_client_options.go#L55>)

WithReceiveMaximum sets the client\-side receive maximum.

```go
type WithReceiveMaximum uint16
```

<a name="WithResponseTopic"></a>
## type [WithResponseTopic](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/alias.go#L58>)

WithResponseTopic sets the response topic for the publish.

```go
type WithResponseTopic = mqtt.WithResponseTopic
```

<a name="WithRetain"></a>
## type [WithRetain](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/alias.go#L61>)

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

```go
type WithRetain = mqtt.WithRetain
```

<a name="WithRetainHandling"></a>
## type [WithRetainHandling](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/alias.go#L64>)

WithRetainHandling specifies the handling of retained messages on the subscribe.

```go
type WithRetainHandling = mqtt.WithRetainHandling
```

<a name="WithSessionExpiry"></a>
## type [WithSessionExpiry](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/session_client_options.go#L52>)

WithSessionExpiry sets the session expiry interval \(in seconds\).

```go
type WithSessionExpiry uint32
```

<a name="WithUserProperties"></a>
## type [WithUserProperties](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/alias.go#L66>)

WithUserProperties sets the user properties for the publish or subscribe.

```go
type WithUserProperties = mqtt.WithUserProperties
```

<a name="WithUsername"></a>
## type [WithUsername](<https://github.com/Azure/iot-operations-sdks/blob/main/go/mqtt/session_client_options.go#L68>)

WithUsername sets the UsernameProvider that the session client uses to get the username for each connection.

```go
type WithUsername UsernameProvider
```

Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)
