Skip to content

Publish via output

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

Output binding

  • Add the MqttAttribute to one of your functions parameters
  • Make sure the type of the parameter is IMqttMessage and marked as out

Example

[FunctionName("SimpleFunction")]
public static void SimpleFunction(
        [TimerTrigger("0 */5 * * * *")]TimerInfo timer,
        [Mqtt("testtopic/out")] out IMqttMessage outMessage)
    {
        outMessage = new MqttMessage("testtopic/in", new byte[] { }, MqttQualityOfServiceLevel.AtLeastOnce, true);
    }

Connection

The connection to the MQTT broker is made when the first message is published and then reused/kept open for later messages.