# MQTT3

Type: `pubsub.mqtt3`

Status: stable

Reference: https://docs.dapr.io/reference/components-reference/supported-pubsub/setup-mqtt3/

## Example

```
apiVersion: cra.diagrid.io/v1beta1
kind: Component
metadata:
  name: <name>
spec:
  type: pubsub.mqtt3
  version: v1
  metadata:
    # Address of the MQTT broker. Use the `tcp://`` URI scheme for non-TLS communication. Use the `ssl://`` URI scheme for TLS communication (requires `caCert`, `clientKey`, `clientCert` to be defined).
    - name: url
      value: "tcp://[username][:password]@host.domain[:port]"
    # Certificate authority certificate, required for using TLS. (Optional)
    #- name: caCert
    #  value: | 
    #    -----BEGIN CERTIFICATE-----
    #    <base64-encoded DER>
    #    -----END CERTIFICATE-----
    # Client certificate, required for using TLS. (Optional)
    #- name: clientCert
    #  value: | 
    #    -----BEGIN CERTIFICATE-----
    #    <base64-encoded DER>
    #    -----END CERTIFICATE-----
    # Client key, required for using TLS. (Optional)
    #- name: clientKey
    #  value: | 
    #    -----BEGIN RSA PRIVATE KEY-----
    #    <base64-encoded DER>
    #    -----END RSA PRIVATE KEY-----
    # When the value is set to "true", sets the clean_session flag in the connection message to the MQTT broker. (Optional)
    #- name: cleanSession
    #  value: "false"
    # Set the consumer ID to control namespacing. Defaults to the app's ID. (Optional)
    #- name: consumerID
    #  value: "{namespace}"
    # Indicates the Quality of Service Level (QoS) of the message. (Optional)
    #- name: qos
    #  value: "1"
    # Defines whether the message is saved by the broker as the last known good value for a specified topic. (Optional)
    #- name: retain
    #  value: "false"

```

## Authentication profiles

Available authentication profiles:

- Connection string

### Connection string

Authenticate using a connection string.

#### `url` (string)

**Required** - Address of the MQTT broker. Use the `tcp://`` URI scheme for non-TLS communication. Use the `ssl://\`\` URI scheme for TLS communication (requires `caCert`, `clientKey`, `clientCert` to be defined).

Example value: `tcp://[username][:password]@host.domain[:port]`

#### `caCert` (string)

Certificate authority certificate, required for using TLS.

Example value:

```
-----BEGIN CERTIFICATE-----\n<base64-encoded DER>\n-----END CERTIFICATE-----
```

#### `clientCert` (string)

Client certificate, required for using TLS.

Example value:

```
-----BEGIN CERTIFICATE-----\n<base64-encoded DER>\n-----END CERTIFICATE-----
```

#### `clientKey` (string)

Client key, required for using TLS.

Example value:

```
-----BEGIN RSA PRIVATE KEY-----\n<base64-encoded DER>\n-----END RSA PRIVATE KEY-----
```

## Metadata

### `cleanSession` (bool)

When the value is set to "true", sets the clean\_session flag in the connection message to the MQTT broker.

Default value: `false`

Example value: `true, false`

MQTT Clean Sessions Example: http://www.steves-internet-guide.com/mqtt-clean-sessions-example/

### `consumerID` (string)

Set the consumer ID to control namespacing. Defaults to the app's ID.

Example value: `{namespace}`

Documentation: https://docs.dapr.io/developing-applications/building-blocks/pubsub/pubsub-overview/#consumer-groups-and-competing-consumers-pattern

### `qos` (number)

Indicates the Quality of Service Level (QoS) of the message.

Default value: `1`

Example value: `2`

Allowed values:

- 0

- 1

- 2

MQTT Essentials - Part 6: https://www.hivemq.com/blog/mqtt-essentials-part-6-mqtt-quality-of-service-levels/

### `retain` (bool)

Defines whether the message is saved by the broker as the last known good value for a specified topic.

Default value: `false`

Example value: `true, false`
