Skip to content

Custom connection

Kees Schollaart edited this page Apr 14, 2018 · 3 revisions

Custom MQTT-Client Configuration

Internally the MQTTnet is used for the Mqtt implementation.

If you need a more complex configuration, for example if you want to

  • use Tls
  • special certificates
  • custom logic for setting the topics/clientId
  • connecting over websockets
  • control the QoS level per topic

To do this, implemented a custom ICreateMqttConfig and provide this Type as parameter to on of the attributes. Both the MqttTriggerAttribute and the MqttAttribute have a constructor overload accepting a Type like this:

public static void MyFunction([MqttTrigger(typeof(MyMqttConfigProvider))]IqttMessage message)

In your implementation of ICreateMqttConfig you need to return an instance of abstract class CustomMqttConfig which requires you to implement a property of type IManagedMqttClientOptions. Examples on how to build an instance of IManagedMqttClientOptions are available in the ManagedClient wiki of MQTTnet.

An example of this custom client configuration is implemented in this function.