This repo contains some sample code experimenting with the new http worker coming in Azure Functions. More details and samples for this feature can be found at Pragna Gopa's repo here.
Essentially, this repo contains 2 simple, dirty, identical APIs: One written in Go and the other in Java. With the new http worker feature, we can spin up our own process along with the functions runtime, and functions will simply marshall requests from triggers + bindings to our own http endpoints.
There is no 'function code' - just json triggers and bindings, which point at our own HTTP endpoints which are not aware of functions.
- Make sure you've got functions core tools installed and up to date -> docs.
- Clone this repo
- Update the values in
local.settings.json
to point at your own storage accounts / cosmos etc as needed
- Build the Go API:
go build ./go/go-http-server
- Rename the
host-go.json
tohost.json
- Package the Java API. Using Maven:
mvn package -f "com.damoo/pom.xml"
- Rename the
host-java.json
tohost.json
- Ensure the path to
java
is correct for your environment. Just'java'
should work given it's on yourPATH
.
- Ensure the path to
- Run the functions host:
func start
- Hit the endpoints in Postman / your api testing tool. For the
add
endpoint, use the following json schema:
{
"id": 1,
"name": "bananas"
}
/api/add
:POST
the above schema/api/get?id=1
:GET
an item/api/list
:GET
all items/api/send-items
:GET
. Send all items to a storage queueprocess-items
(non-http): Trigger on queue and post to cosmos and secondary queue
It's also possible - and in this case probably desirable - to containerise your functions. This can help smooth the deployment too. The Dockerfile found in this repo uses the standard node image for functions, and installs Java 11 into it.
Build:
docker build -t myregistry.azurecr.io/javafunc:1 .
Push:
docker push myregistry.azurecr.io/javafunc:1
Wire up:
Create a new function app and select Container
as the runtime - follow the wizard to point it to your pushed container in your registry. More found here.
All code is sample, ugly, and likely to break :)