This repository contains the code for the CaseOnline.Azure.WebJobs.Extensions.Mqtt NuGet Package.
This package enables you to:
- Trigger an Azure Function based on a MQTT Subscription
- Publish a message to a MQTT topic as a result of an Azure Function
Are you curious what MQTT is? Check this page!
Important note when using MQTT triggers: This extension only works when you use AppService Plan! Do not use this with Consumption plan. If you're only using the output binding, using consumption plan is fine!
- Getting Started
- Publish via output
- Subscribe via trigger
- Integrate with Azure IoT Hub
- And more in the Wiki
Install stable releases via Nuget; development releases are available via MyGet.
Master > NuGet | Dev > MyGet | |
---|---|---|
Build status | ||
Deployment Status | ||
Package |
This is a simple example, receicing messages for topic my/topic/in
and publishing messages on topic testtopic/out
.
public static class ExampleFunctions
{
[FunctionName(nameof(SimpleFunction))]
public static void SimpleFunction(
[MqttTrigger("my/topic/in")] IMqttMessage message,
[Mqtt] out IMqttMessage outMessage,
ILogger logger)
{
var body = message.GetMessage();
var bodyString = Encoding.UTF8.GetString(body);
logger.LogInformation($"{DateTime.Now:g} Message for topic {message.Topic}: {bodyString}");
outMessage = new MqttMessage("testtopic/out", new byte[] { }, MqttQualityOfServiceLevel.AtLeastOnce, true);
}
}
Please find all working examples in the sample project.
Copyright (c) 2020 Kees Schollaart
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.