Asked by:
Digital Twins User Defined Functions: How to write an User Defined Function that passes processed telemetry messages to Event Hubs Endpoint?

Question
-
Hello all,
I have an Azure Digital Twins resource currently deployed and I am hoping to post a few user defined functions in there that would perform some sort of processing on the telemetry messages that it receives. - In reference to this article: https://docs.microsoft.com/bs-latn-ba/azure/digital-twins/how-to-user-defined-functions
However, I would also like to push said telemetry messages to an external (but within Azure) Event Hubs endpoint. Should this forwarding be specified in my user defined function? - If so, how would I modify my user defined functions such that it passes the telemetry messages to my Event Hubs endpoint?
Thank you in advance!
All replies
-
Hello Synovia,
If you want to route all device messages to an Event Hub you will need to add the type "DeviceMessage" when configuring the routing endpoint. Eg:
{ "type": "EventHub", "eventTypes": [ "DeviceMessage" ], "connectionString": "Endpoint=sb://YOUR_NAMESPACE.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=YOUR_PRIMARY_KEY;EntityPath=YOUR_EVENT_HUB_NAME", "secondaryConnectionString": "Endpoint=sb://YOUR_NAMESPACE.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=YOUR_SECONDARY_KEY;EntityPath=YOUR_EVENT_HUB_NAME", "path": "YOUR_EVENT_HUB_NAME" }
Note (as of today):
- DeviceMessage is combinable only with EventHub. You can't combine DeviceMessage with any of the other event types.
- You can specify only one endpoint of the combination of type EventHub or DeviceMessage.
Thanks!
- Proposed as answer by António Sérgio Azevedo - MSFTMicrosoft employee, Moderator Wednesday, June 19, 2019 10:43 AM
- Unproposed as answer by António Sérgio Azevedo - MSFTMicrosoft employee, Moderator Tuesday, July 2, 2019 11:42 AM
-
Hello Antonio,
Thank you for your reply. I have implemented this endpoint configuration into Azure Digital Twins already. I am still a tad lost. Would a telemetry message, after being processed in some manner by a User Defined Function and sent to an Event Hubs Endpoint, still be considered as DeviceMessage or as a UdfCustom event type?
Thanks.
-
Hello Synovial,
By reading the doc it is clear that you can't combine both eventType "DeviceMessage" and "UdfCustom" into the endpoint type "EventHub".
Therefore if your configuration is like:
{ "type": "EventHub", "eventTypes": [ "UdfCustom" ], "connectionString": "Endpoint=sb://YOUR_NAMESPACE.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=YOUR_PRIMARY_KEY;EntityPath=YOUR_EVENT_HUB_NAME", "secondaryConnectionString": "Endpoint=sb://YOUR_NAMESPACE.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=YOUR_SECONDARY_KEY;EntityPath=YOUR_EVENT_HUB_NAME", "path": "YOUR_EVENT_HUB_NAME" }
Then the event sent by a user-defined function (UDF) will be considered as "UdfCustom" eventType.
- Proposed as answer by António Sérgio Azevedo - MSFTMicrosoft employee, Moderator Tuesday, July 2, 2019 11:42 AM
-