Skip to content

Wrapping Go & Java Spring APIs in Azure Functions (Functions HTTP Worker experimentation)

Notifications You must be signed in to change notification settings

damoodamoo/azure-func-go-java

Repository files navigation

Azure Functions with Go / Java Spring

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.

Structure

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.

To Run

  • 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

Using the Go API

  • Build the Go API:
go build ./go/go-http-server
  • Rename the host-go.json to host.json

Using the Java API

  • Package the Java API. Using Maven:
mvn package -f "com.damoo/pom.xml"
  • Rename the host-java.json to host.json
    • Ensure the path to java is correct for your environment. Just 'java' should work given it's on your PATH.

Run it...

  • 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"
}

Operations:

  • /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 queue
  • process-items (non-http): Trigger on queue and post to cosmos and secondary queue

Use the container

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.

Disclaimer

All code is sample, ugly, and likely to break :)

About

Wrapping Go & Java Spring APIs in Azure Functions (Functions HTTP Worker experimentation)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published