How to trigger and query an Azure Entity Function without using an ordinary function - just use the built in HTTP webhooks!

by Patrick Lee on 08 May 2022 in categories BigData tech with tags AzureFunctions DurableFunctions Functions

I recently revisited creating Entity Functions (previously called  Durable Entities) for a long running task, which needs to be queried as to its progress.

In the past I have had to use a standard Azure function to trigger a Durable Entity, but recently discovered that this isn't necessary.

Instead (see https://docs.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-http-api) Azure provides webhooks that you can call.

First, create the entity by calling an operation on it via a POST call

You first need to create the entity by calling an operation on it, via a url similar to the following: 

POST /runtime/webhooks/durabletask/entities/{entityName}/{entityKey}
    ?taskHub={taskHub}
    &connection={connectionName}
    &code={systemKey}
    &op={operationName}

That will both create the instance of the Entity (of type entityName and with uniqueId entityKey) and call the operation called operationName on it.

It should return a 202 Accepted code.

Query the state of the entity (e.g. progress) via a GET call

Once the entity has been created you can then get the exposed state of the entity via a url similar to the following

GET /runtime/webhooks/durabletask/instances/{instanceId}
    ?taskHub={taskHub}
    &connection={connectionName}
    &code={systemKey}
    &showHistory=[true|false]
    &showHistoryOutput=[true|false]
    &showInput=[true|false]
    &returnInternalServerErrorOnFailure=[true|false]

This should return a 200 OK code, with a body showing the publicly exposed properties of the entity.

Conclusion

Using these built in webhooks means that you can avoid having to create a separate (non durable) Azure function and an associated trigger for that function.

Very neat!