spring-bootazure-spring-cloudazure-spring-boot

Auto assigned nodeId for azure spring app or how to get app instance name


In azure spring boot app while having multiple instances I need to get somehow its app instance name, or would be perfect to configure nodeId generation ( int/long type , but if now I can live with name ). Anyone knows how to access this data from code ?


Solution

  • To get app instances name list from application code, you may try to use the following REST API:

    1. To list all the instances names in an app, we can use
    GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AppPlatform/Spring/{serviceName}/apps/{appName}/deployments?api-version=2022-12-01
    

    You should be able to find all the instances name in the response json file.

    {
      "value": [
        {
          "properties": {
            ...,
            "instances": [
              {
                "name": "<app name>-<deployment name>-x-xxxxxxxx-xxxx",
                "status": "Running",
                "discoveryStatus": "UP",
                "startTime": "2023-xx-xxTxx:xx:xxZ"
              },
              ...
            ],
    

    Reference doc: https://learn.microsoft.com/en-us/rest/api/azurespringapps/deployments/list?tabs=HTTP

    1. To list all the instances names in the Azure Spring Apps service:
    GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AppPlatform/Spring/{serviceName}/deployments?api-version=2022-12-01
    

    You can find the instance list in the 'properies' -> 'instances' of the request response.

    Reference doc: https://learn.microsoft.com/en-us/rest/api/azurespringapps/deployments/list-for-cluster?tabs=HTTP

    1. You can also use Azure Resource Manager App Platform client library for Java SDK to access the information in your code.

    Reference doc: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/resourcemanager/azure-resourcemanager-appplatform