0

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 ?

FrancMo
  • 2,459
  • 2
  • 19
  • 39

1 Answers1

1

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

hanli
  • 91
  • 2
  • thanks but its listing all not current one – FrancMo Jan 17 '23 at 09:42
  • 1
    For the current app instance name, we can read from the environment variable HOSTNAME. It should look like this: HOSTNAME=--x-xxxxxxxx-xxxx – hanli Jan 20 '23 at 07:58