keesschollaart81 / caseonline.azure.webjobs.extensions.mqtt Goto Github PK
View Code? Open in Web Editor NEWMqtt Bindings for Azure Functions!
License: MIT License
Mqtt Bindings for Azure Functions!
License: MIT License
Redirects to https://github.com/keesschollaart81/CaseOnline.Azure.WebJobs.Extensions.Mqtt/blob/master/wiki/Getting-started which gives a 404.
I tried following the instruction but end up with a lot of versioning conflicts, such as for Newtonsoft.Json. Could you maybe update the readme with sample PackageReferences
?
I got the SimpleFunction example working to subscribe to an topic, let's say "my/topic/test". However if I set the topic to wildcard "my/topic/#" then the trigger does not pick up. Am I missing something?
After configuring the broker with certificates and also using the MqttClientOptionsBuilderTlsParameters when setting up the connection to the broker from the Azure Function trigger, we immediately get the MqttCommunicationClosedGracefullyException after deploying the Function to the Azure resource.
This issue exists solely when running on Azure, for local debugging of the Function, it works just fine.
Are there any ideas as to why this happens?
Hi,
according to this document on Azure Functions Binding Syntax it should be possible to access the Application Settings of a Functions App by using the %AppSetting%
syntax in the definition of a binding. Unfortunately this doesn't seem to work in my code which is implemented as follows:
[FunctionName("OnDeviceCreate")]
public static async Task OnDeviceCreate([MqttTrigger(typeof(TTNMqttConfigProvider), "%TTNAppID%/devices/+/events/create")] IMqttMessage message, ILogger logger)
{
logger.LogInformation($"{DateTime.Now:g} Creation message for topic {message.Topic}");
....
Is there another way to access Application Settings from an MqttTrigger Binding Definition?
Thanks in advance!
Hi @keesschollaart81 ,
First i would like to thank you for this implementation of MQTT in Azure Function, it really helps.
I have the fallowing scenario.
I want to connect to a MQTT broker but the password expire after a certain time and i need to updated it and restart the MQTT client.
Is there a way to implement custom authentication?
Thank you
[MqttTrigger(typeof(MqttConfigProvider), "TOPIC/#")]IMqttMessage message, ILogger log)
How can I subscribe several topics at same time from a message broker?
Please, describe some ways with code...
The ManagedClient of MQTTNet doesn't support clean session as false. How can use cleansession:false with this extension?
Hi,
I have assigned two triggers for different topics to two functions as in the following code snippet:
public static class TTNAzureDeviceManagement
{
[FunctionName("OnDeviceCreate")]
public static async Task OnDeviceCreate([MqttTrigger(typeof(TTNMqttConfigProvider), "ttn-mapper-jsi/devices/+/events/create")] IMqttMessage message, ILogger logger)
{
logger.LogInformation($"{DateTime.Now:g} Creation message from topic {message.Topic}");
....
}
[FunctionName("OnDeviceDelete")]
public static async Task OnDeviceDelete([MqttTrigger(typeof(TTNMqttConfigProvider), "ttn-mapper-jsi/devices/+/events/delete")] IMqttMessage message, ILogger logger)
{
logger.LogInformation($"{DateTime.Now:g} Deletion message from topic {message.Topic}");
....
}
}
When I now run these function on Azure and send a message to one of the topics (e.g. devices/+/events/create) both functions are executed as can be seen in the following log:
2019-03-10T12:36:11.741 [Information] Executing 'OnDeviceCreate' (Reason='Mqtt fired at 2019-03-10T12:36:11.7416672+00:00', Id=84a4a1e1-136d-4cd6-847d-4c79fc5311c6)
2019-03-10T12:36:11.743 [Information] 3/10/2019 12:36 PM Creation message from topic ttn-mapper-jsi/devices/test/events/delete
2019-03-10T12:36:11.788 [Information] 3/10/2019 12:36 PM Added device test to IoT Hub
2019-03-10T12:36:11.788 [Information] Executed 'OnDeviceCreate' (Succeeded, Id=84a4a1e1-136d-4cd6-847d-4c79fc5311c6)
Notice that the "OnDeviceCreate" function was executed while the topic which was triggered was "devices/test/events/delete". The "OnDeviceDelete" functions is executed as well but that's in another log.
Is this a bug or am I doing something wrong here?
Thanks in advance!
In order to minimize costs.. is it possible to publish this as an azure webjob instead of function? (The naming indicates something in that direction)
Hi,
When using this extension with an Azure Function v2 or v3 in Visual Studio I get the following error message when running locally:
"The 'TestSubscriberFunction' function is in error: Unable to configure binding 'message' of type 'mqttTrigger'. This may indicate invalid function.json properties. Can't figure out which ctor to call."
The function seems to work anyway because I do get data from the MQTT Broker I connect to but I am not sure if this error message is causing something else to not work within the Function framework.
If there is exceptions regarding to connection then the azure function app will be hung.
These are exceptions:
This is the information from MS support.
“Our current speculation is that, when the function was running, the target server refused the connection for some reason which caused the function code stuck in deadlock. This also leads to the function process hanging the whole time.”
Is there anyone meet this issue?
Hey,
I understand that each Function needs it's own connection to the MQTT-broker. But is there a way to reuse the same connection string?
I have a need for at least three functions subscribing to the same MQTT-broker, listening for different topics. It seems redundant to have to declare three identical connection strings just to make them understand that they need a new connection...
[FunctionName("TestReceiver")]
public static void TestReceiver([MqttTrigger("test/#")]IMqttMessage message, ILogger log)
{
log.LogInformation("TestReceiver function triggered!");
var body = message.GetMessage();
var bodyString = Encoding.UTF8.GetString(body);
log.LogInformation($"TestReceiver, topic {message.Topic}: {bodyString}");
}
[FunctionName("TestDeviceReceiver")]
public static void TestDeviceReceiver([MqttTrigger("device/#")] IMqttMessage message, ILogger log)
{
log.LogInformation("TestDeviceReceiver function triggered!");
var body = message.GetMessage();
var bodyString = Encoding.UTF8.GetString(body);
log.LogInformation($"TestDeviceReceiver, topic {message.Topic}: {bodyString}");
}
Hello. I am trying to write an Azure Function which subscribes to some topics on a MQTT broker, but I am not able to complete the authentication...
I mean: I am using a connection string like:
"MqttConnection": "Server=my.server.com;Username=12345;Password=mypassword"
but if I attach the debugger to the MQTT broker (based on MQTTnet) is see that both username and password in the MqttServer's authentication validator are always null (and so the MQTT broker validator implementation refuses the connection).
Am I forgetting something?
If I modify the broker implementation for accepting any username/password (even null) then everything else works perfectly fine... so I am close to the success, but still missing the authentication part... can anybody help? Thanks.
By default the MQTT subscription happens at QoS 1. Is there an option for subscribing at QoS 2 or 0 ?
I am not sure why disconnect between my broker and function app which delivery telemetry message to table storage in Azure. The connection is working very well during several hours, but after then disconnected them and not reconnected again.
Why is that happening? Could you give me some comments to fix?
Below is my code.
public static void Run( [MqttTrigger(typeof(MqttConfigProvider), "TOPIC/#1", "TOPIC/#2", TOPIC/#3", "TOPIC/#4")]IMqttMessage message, ILogger log)
{
....
}
public class MqttConfigProvider : ICreateMqttConfig
{
public CustomMqttConfig Create(INameResolver nameResolver, ILogger logger)
{
var connectionString = new MqttConnectionString(nameResolver.Resolve("MqttConnection"), "CustomConfiguration");
var options = new ManagedMqttClientOptionsBuilder()
.WithAutoReconnectDelay(TimeSpan.FromSeconds(5))
.WithClientOptions(new MqttClientOptionsBuilder()
.WithClientId(connectionString.ClientId.ToString())
.WithTcpServer(connectionString.Server, connectionString.Port)
.WithCleanSession()
.Build())
.Build();
return new MqttConfigExample("CustomConnection", options);
}
}
public class MqttConfigExample : CustomMqttConfig
{
public override IManagedMqttClientOptions Options { get; }
public override string Name { get; }
public MqttConfigExample(string name, IManagedMqttClientOptions options)
{
Options = options;
Name = name;
}
}
Hey,
We meet the SNAT Port Exhaustion issue on Azure Function when using this Lib. Does anyone know about this SNAT issue and how to solve it?
I am appreciated any help.
Hi, the library is great and it's something It really fits to my needs right now. I was just curious if it's possible to set one connection for input and another one for output? My use case is to subscribe to one and to publish filtered messages to another broker.
Is it possible to use this extension with JS functions? And, if so, could you provide an example?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.