Working With Multiple Function Apps Using Microsoft Tye

Working With Multiple Function Apps Using Microsoft Tye

Recently there is a trend to use serverless component and services to get best use of cloud. In this article I am mainly talk about Azure Cloud and serverless component like Azure Functions.

In my scenario, there is requirement to use function app as a microservice or api end point. This works great in cloud but local development tooling is not that good as of now. If you want to run multiple function apps means services then it is not easy.

Consider a scenario that there is one service to create customer and on creation of customer it publish message and other service like order will create some basic record based on customer information. In this case when checking this end to end we need both service running locally and in microservice development with some product, there are many services like 30,50,100... depends on requirement.

For example I will so you how can you use Microsoft Tye to run multiple service on local development easily and manageable way.

Environment

  • Visual Studio 2022 Community Edition

  • Azure Functions v4 ( dotnet 6 isolated)

  • donet 6 sdk

Steps

  • Create first function app ( Customer service) from Visual Studio. Choose project type Azure Functions.

  • Click "Next" and give name "CustomerService"

  • Click "next" and now you see following screen.

image.png

  • For this demo choose ".NET 6 Isolated" , "Http Trigger" and Authorization level as Anonymous.

  • Click "next" and now Customer service function app get created.

  • Follow above steps for other service like "OrderService".

By default each function app configured to run at port 7071. It can be change to different port and I have covered that part in article Configure Port for Function App. For one or two apps this is good but longer run it become problem.

My solution explorer look like following.

image.png

Now we try to run this with help of microsoft tye.

At the time of writing this article Microsoft Tye still in preview mode with version "0.11.0-alpha.22111.1". Nuget link https://www.nuget.org/packages/Microsoft.Tye

  • Open command prompt.

  • Execute following command to install Microsoft Tye

dotnet tool install --global Microsoft.Tye --version 0.11.0-alpha.22111.1
  • Once that tool install successfully, go to solution explorer.

  • Add file called tye.yml and add following content. This is minimal setup required.

name: myservices
services:
- name: customerservice
  azureFunction: customerservice/
- name: orderservice
  azureFunction: orderservice/
  • Now go to command prompt and root at the location where tye.yml file is present. This structure looks like following at directory level.

image.png

  • run command. tye run
C:\Users\jinal\source\repos\MultipleFunctionApps>tye run
  • On successful execution it will display message like following.

image.png

It will run orderservice at port 26162 and customer service at 26161.

image.png

  • On click of "View" link of log column you can see log as well.

Above points are almost what it is required to do. Only problem with above approach is that if you run it second time then it will no guarantee that same service will give same port. So if you are using some kind of service discovery then it is fine otherwise it is problem. Following is the solution to that.

  • Open tye.yml file and provide bindings.
name: myservices
services:
- name: customerservice
  azureFunction: customerservice/
  bindings:
   - port: 7071
- name: orderservice
  azureFunction: orderservice/
  bindings:
   - port: 7072
  • stop and run tye run again.

  • refresh the web portal for tye. Now you can see following things.

image.png

Note: Microsoft Tye is currently in development and preview mode. There is chance that it will change for certain configuration and I will try to keep update once final release available.

Source code: MutipleFunctionApps