Azure Function App and IoT Hub Event hub - azure

I have a Azure Function App which is bound as a trigger to Azure IoT Hub Event Hub.
As soon as any event is received by IoT Hub it triggers the Function App function and the message is received inside the Function App.
I want to re-raise the triggers for old events and want them on Function App right from the beginning. How can I refire the IoT Hub events so that the Function App can receive them from the beginning?
Thanks

You may create another consumer group for your EventHub and configure your Function's function.json to listen to that consumer group. This will allow your Function to read messages from the very beginning.

Related

Simulated device with Azure Function on IoT Hub is not able to trigger

Currently I have simulated device that receives message from IoT Hub and processes it and after it is done, device sends message to IoT Hub. The device is working but it is running as .exe file on computer and Im trying to transform it and upload on Azure as function so I can avoid it not working when computer turns off or freezes while Im not around it.
I wanted to make it function triggered by events on IoT Hub but Im facing problem. Currently the function that sends message, sends it directly to device on IoTHub(my device) but in case like this, message is not "displayed" on IoT Hub so Im unable to use it as trigger. I'm unable to change function that sends message to device. Are there any options how to catch those messages on IoTHub or possibility to trigger it any other way?
There is no direct way to send messages from Azure function to Azure IoT Hub. You can probably utilize Device event Azure IoT Hub Rest API end point from the Azure Function and send the message to the Azure IoT Hub. Here is the request you can make to send the message to Azure IoT Hub.
POST https://fully-qualified-iothubname.azure-devices.net/devices/{id}/messages/events?api-version=2020-03-13
Please find the following reference to all the Supported bindings for Azure Functions runtime
You can trigger the Azure Function by using the IoT Hub trigger. Refer the following resource that runs you through the steps needed to set up the Azure IoT Hub trigger for Azure Functions

send events from Azure Service Bus Topic to Event Hub

I want to send an event that is sent to Azure Service Bus topic to an event hub. Is this possible?
Details:
I am working with a different team in my company that receives third party events (via webhook) to Azure Service Bus topic and this is further used in different application.
My team wants to now listen/subscribe to this topic using our existing event hub and using azure capture store these events to a storage account.
I did the following:
I created a subscription to their topic in their Azure Service Bus.
I created an event hub in my Event hub namespace.
I am not sure, how to now connect the azure service bus topic subscription to send those events to my event hub.
Thanks for your time.
Service bus operates with the receivers having to pull messages from it. This is opposite to Eventgrid which pushes the events to its subscribers. Eventhub does not pull messages from the source, we need to push messages into it. So you cannot achieve your requirement without an extra component between Service Bus and Eventhub.
One of the possible components would be a service bus topic triggered azure function LINK which writes into the eventhub using output binding LINK or the SDK LINK.
You will need to choose your service plan carefully depending on the volume of messages expected but usually Consumption plan will suit this purpose.

IoT Hub message routing with DeviceLifecycleEvents source does not work

I am already using an IoT Hub and have configured message routing to route TwinChangeEvents to an Event Hub. An Azure function with an EventHubTrigger processes the messages. This works perfectly fine.
Now, I wanted to configure message routing to route DeviceLifecycleEvents to another Event Hub. Again, another Azure function with an EventHubTrigger should process the messages.
However, the function is not triggered when I connect or disconnect devices.
When I change the data source of the message routing to TwinChangeEvents, the function is triggered as expected (with the wrong messages of course). That said, I am pretty confident that my configuration of the Event Hub and the Function is correct.
Also, I have tried to configure an Event Subscription in the IoT Hub with for the lifecycle events to the Event Hub. I think this option uses an Event Grid. Anyways, the function gets triggered as expected with this configuration. The problem only occurs when using message routing for the lifecycle events.
Can anyone point me towards a solution why the message routing does not work? Am I missing a configuration in the IoT Hub?
Unfortunately, Event hub doesn't support device connected and disconnected events. This has been confirmed by Microsoft support too. Below is the reply I got from them:-
IoT Device Lifecycle events designed only for device create and delete events. From the description you want your IoT Hub to trigger following events to your Event Hub: Device Created Device Deleted Device Connected Device Disconnected With this requirement you should create a new Event Subscription with Event Grid instead of configuring the IoThub message routing with Device Lifecycle Events as data source. Please go to the IoT Hub and create a new Event Subscription by this path: IoT Hub->Events->+Event Subscription
At the end of the day, I created a event subscription for all device life cycle events and routed them to my custom event hub endpoint. I think you can also do the same, If you want to only subscribe to the Event hub but not Event Grid.
EDIT:- Message routing now supports Device connection state events. Non telemetry events supported by Event hub message routing.
Finally, if a route is created with data source set to device
connection state events, IoT Hub sends a message indicating whether
the device was connected or disconnected.

Azure IoT Hub - IoTHubTrigger Azure function doesn't execute if a route is set up on the IoT Hub

I have an IoTHubTrigger Azure function that processes the events from the IoT Hub.
It works as expected until I add a new Route in "Message routing" setting of the IoT Hub to send events to another event hub. In which case, the events successfully get routed to the event hub but don't hit the IoTHubTrigger Azure function anymore. Worth mentioning that the only options I have as endpoints to for route are Event Hubs, Service Bus Queue, Service Bus Topic and Storage.
Is there a way for me to have it route to both, the azure function and the event hub?
The following route will forward all telemetry messages to the default endpoint such as a built-in iot hub endpoint events:

How to make use of Function Apps for Azure IoT Hub?

So I've been trying to generate a small function app (in JS) that responds to a message sent to the Azure IoT Hub. The output is a simple console log. However, I am unable to load the event hub compatible end point of the IoT Hub as the trigger (the only option available is to create a new Event Hub). How do I proceed? The code for the device to send to Azure' IoT Hub is working and I am able to view the messages via the Device Explorer tool.
You need to create new Event Hub Connection and use the Event Hub-Compatible endpoint from the Iot Hub Messaging section.
But you need to change it to match the service bus connection string format -
"Endpoint=[your iot hub compatible end point];SharedAccessKeyName=[your key name];SharedAccessKey=[your key];EntityPath=[your event hub compatible name]"
key name and key can be taken from the "Shared access policy" section.
Good Luck

Resources