From 3f28cd0c61d075e5160881e24b5f5f2a9615673f Mon Sep 17 00:00:00 2001 From: Kees Schollaart Date: Sun, 25 Mar 2018 20:45:05 +0200 Subject: [PATCH] Updating the readme --- README.md | 16 ++++++++++------ .../Bindings/AttributeToConfigConverter.cs | 3 ++- ...seOnline.Azure.WebJobs.Extensions.Mqtt.csproj | 2 +- .../Config/MqttExtensionConfigProvider.cs | 1 - .../Listeners/MqttListener.cs | 6 +++--- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index de73b2b..2b6bad0 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,11 @@ This is a work-in-progress of a Mqtt Trigger for Azure Functions. The code currently works as it is but I have to make it better configurable before I publish it as a NuGet Package. Things that have to be done: -- Unit Tests & Integration tests -- extensions.json is now manually created, which should not be needed -- Use ILogger instead of TraceWriter which currently does not output for some reason? -- Figure out if this is stable in the long run, will the connection persist days (currently tested for hours) +- Create more Unit Tests & Integration tests and get code coverage to >80% +- Use ILogger instead of TraceWriter which currently does not output on dev machine for some reason? +- Create demos for integrations with CloudMqtt.net and Azure IoT Hub + +Expect a NuGet package halfway April '18. [![Build Status](https://caseonline.visualstudio.com/_apis/public/build/definitions/4df87c38-5691-4d04-8373-46c830209b7e/11/badge)](https://caseonline.visualstudio.com/CaseOnline.Azure.WebJobs.Extensions.Mqtt/_build/index?definitionId=1) [![BCH compliance](https://bettercodehub.com/edge/badge/keesschollaart81/CaseOnline.Azure.WebJobs.Extensions.Mqtt?branch=master)](https://bettercodehub.com/) @@ -15,14 +16,13 @@ The code currently works as it is but I have to make it better configurable befo - Create an Azure Function using [Visual Studio](https://docs.microsoft.com/en-us/azure/azure-functions/functions-develop-vs) or using [Visual Studio Code](https://code.visualstudio.com/tutorials/functions-extension/getting-started) - Make sure your ```Microsoft.NET.Sdk.Functions``` package version is 1.0.7 or higher - Install the [CaseOnline.Azure.WebJobs.Extensions.Mqtt](https://www.nuget.org/packages/CaseOnline.Azure.WebJobs.Extensions.Mqtt/) NuGet package in you Functions Project -- Add an [extensions.json](./src/ExampleFunctions/extensions.json) to your Functions project root directory and [make sure it is copied to the build/publish folder](./src/ExampleFunctions/ExampleFunctions.csproj#L23-L25) - - This is temporary for now. This should not be needed, monitor [issue/bug here](https://github.com/Azure/Azure-Functions/issues/624)) - Add the Mqtt server settings to your 'local.settings.json' during development time or to your appsettings when running on Azure: - MqttServer (just the dns/hostname) - MqttUsername - MqttPassword - MqttPort (optional, defaults to 1883) - MqttClientId (optional, defaults to a random Guid) +- When deploying/running on Azure set/ad the application-setting ```FUNCTIONS_EXTENSION_VERSION``` to ```beta``` - Add a ```MqttTrigger``` attribute to your function parameters: ``` @@ -55,6 +55,10 @@ Please find some samples here in the [sample project](./src/ExampleFunctions/). ## References - [MQTTnet](https://github.com/chkr1011/MQTTnet) +## Roadmap +- 1.0.0 Initial release, april 2018 +- 1.5.0 Output binding for publishing messages june 2018 + ## MIT License Copyright (c) 2018 Kees Schollaart diff --git a/src/CaseOnline.Azure.WebJobs.Extensions.Mqtt/Bindings/AttributeToConfigConverter.cs b/src/CaseOnline.Azure.WebJobs.Extensions.Mqtt/Bindings/AttributeToConfigConverter.cs index 98943d0..d4fd6f7 100644 --- a/src/CaseOnline.Azure.WebJobs.Extensions.Mqtt/Bindings/AttributeToConfigConverter.cs +++ b/src/CaseOnline.Azure.WebJobs.Extensions.Mqtt/Bindings/AttributeToConfigConverter.cs @@ -57,7 +57,8 @@ private MqttConfiguration GetConfigurationViaAttributeValues() clientId = Guid.NewGuid().ToString(); } - var server = _nameResolver.Resolve(_mqttTriggerAttribute.ServerName ?? SettingsKeyForServer); + var server = _nameResolver.Resolve(_mqttTriggerAttribute.ServerName ?? SettingsKeyForServer); + if (string.IsNullOrEmpty(server)) throw new Exception("No server hostname configured, please set the server via the MqttTriggerAttribute, using the application settings via the Azure Portal or using the local.settings.json"); var username = _nameResolver.Resolve(_mqttTriggerAttribute.UsernameName ?? SettingsKeyForUsername); var password = _nameResolver.Resolve(_mqttTriggerAttribute.PasswordName ?? SettingsKeyForPassword); diff --git a/src/CaseOnline.Azure.WebJobs.Extensions.Mqtt/CaseOnline.Azure.WebJobs.Extensions.Mqtt.csproj b/src/CaseOnline.Azure.WebJobs.Extensions.Mqtt/CaseOnline.Azure.WebJobs.Extensions.Mqtt.csproj index ef87fd6..5544e86 100644 --- a/src/CaseOnline.Azure.WebJobs.Extensions.Mqtt/CaseOnline.Azure.WebJobs.Extensions.Mqtt.csproj +++ b/src/CaseOnline.Azure.WebJobs.Extensions.Mqtt/CaseOnline.Azure.WebJobs.Extensions.Mqtt.csproj @@ -9,7 +9,7 @@ https://github.com/keesschollaart81/CaseOnline.Azure.WebJobs.Extensions.Mqtt git https://github.com/keesschollaart81/CaseOnline.Azure.WebJobs.Extensions.Mqtt/blob/master/LICENSE - 1.0.0-beta3 + 1.0.0-beta4 azure functions mqtt webjobs trigger binding function webjob CaseOnline.Azure.WebJobs.Extensions.Mqtt CaseOnline.Azure.WebJobs.Extensions.Mqtt diff --git a/src/CaseOnline.Azure.WebJobs.Extensions.Mqtt/Config/MqttExtensionConfigProvider.cs b/src/CaseOnline.Azure.WebJobs.Extensions.Mqtt/Config/MqttExtensionConfigProvider.cs index 89f2cee..0a83282 100644 --- a/src/CaseOnline.Azure.WebJobs.Extensions.Mqtt/Config/MqttExtensionConfigProvider.cs +++ b/src/CaseOnline.Azure.WebJobs.Extensions.Mqtt/Config/MqttExtensionConfigProvider.cs @@ -15,7 +15,6 @@ public void Initialize(ExtensionConfigContext context) context.Trace.Info("MqttExtensionConfigProvider.Initialize() called!"); var logger = context.Config.LoggerFactory.CreateLogger(LogCategories.CreateTriggerCategory("Mqtt")); - logger.LogWarning("Logger not working?"); _nameResolver = context.Config.GetService(); diff --git a/src/CaseOnline.Azure.WebJobs.Extensions.Mqtt/Listeners/MqttListener.cs b/src/CaseOnline.Azure.WebJobs.Extensions.Mqtt/Listeners/MqttListener.cs index bf0f693..750b2d7 100644 --- a/src/CaseOnline.Azure.WebJobs.Extensions.Mqtt/Listeners/MqttListener.cs +++ b/src/CaseOnline.Azure.WebJobs.Extensions.Mqtt/Listeners/MqttListener.cs @@ -122,17 +122,17 @@ public void Execute(object stateInfo) private void ManagedMqttClientDisconnected(object sender, MqttClientDisconnectedEventArgs e) { - _traceWriter.Error($"MqttListener._client_Disconnected, was :{e.ClientWasConnected} for {Descriptor}", e.Exception); + _traceWriter.Error($"MqttListener Disconnected, previous connectivity state '{e.ClientWasConnected}' for {Descriptor}", e.Exception); } private void ManagedMqttClientConnected(object sender, MqttClientConnectedEventArgs e) { - _traceWriter.Info($"MqttListener._client_Connected {e.IsSessionPresent} for {Descriptor}"); + _traceWriter.Info($"MqttListener Connected {e.IsSessionPresent} for {Descriptor}"); } private void ManagedMqttClientApplicationMessageReceived(object sender, MqttApplicationMessageReceivedEventArgs e) { - _traceWriter.Info("Mqtt client receiving message for {descriptor}"); + _traceWriter.Info($"MqttListener receiving message for {Descriptor}"); InvokeJobFunction(e).Wait(); }