MQTT

To setup MQTT pubsub create a component of type . See this guide on how to create and apply a pubsub configuration

Warning

The above example uses secrets as plain strings. It is recommended to use a secret store for the secrets as described here.

To configure communication using TLS, ensure that the MQTT broker (e.g. mosquitto) is configured to support certificates and provide the caCert, clientCert, clientKey metadata in the component configuration. For example:

Consuming a shared topic

When consuming a shared topic, each consumer must have a unique identifier. By default, the application ID is used to uniquely identify each consumer and publisher. In self-hosted mode, invoking each dapr run with a different application ID is sufficient to have them consume from the same shared topic. However, on Kubernetes, multiple instances of an application pod will share the same application ID, prohibiting all instances from consuming the same topic. To overcome this, configure the component’s consumerID metadata with a {uuid} tag, which will give each instance a randomly generated consumerID value on start up. For example:

Warning

The above example uses secrets as plain strings. It is recommended to use a secret store for the secrets as described .

You can run a MQTT broker locally using Docker:

You can run a MQTT broker in kubernetes using following yaml:

You can then interact with the server using the client port: tcp://mqtt-broker.default.svc.cluster.local:1883