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

  • 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!

    Monday, June 17, 2019 2:54 PM

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!

    Wednesday, June 19, 2019 10:43 AM
    Moderator
  • 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.

    Monday, June 24, 2019 12:54 PM
  • 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.

    Tuesday, July 2, 2019 11:42 AM
    Moderator
  • Hi Synovial,

    Please let us know if we answered your questions and if so please mark it as answer so others can benefit from this as well :).

    Thanks!

    Wednesday, July 17, 2019 3:03 PM
    Moderator