Skip to content

Latest commit

 

History

History
56 lines (42 loc) · 3.15 KB

File metadata and controls

56 lines (42 loc) · 3.15 KB

Access Azure Spring Apps managed Spring Cloud Service Registry

This sample shows how to access Azure Spring Apps managed Spring Cloud Service Registry through Azure RBAC when your applications are running outside Azure Spring Apps.

Prerequisite

How to run

  1. Clone this repo and go to folder

    git clone https://github.com/Azure-Samples/azure-spring-apps-samples
    cd azure-spring-apps-samples/custom-eureka-client
  2. Install Azure CLI extension for Azure Spring Apps

    az extension add --name spring-cloud
  3. Create an instance of Azure Spring Apps

    az spring-cloud create -n <service name> -g <resource group name>
  4. Create a service principal to access the Config Server in your application.

    az ad sp create-for-rbac --scopes /subscriptions/<subscription id>/resourceGroups/<resource group name>/providers/Microsoft.AppPlatform/Spring/<service name> --role "Azure Spring Cloud Service Registry Contributor"

    The output includes credentials you will need in the next step.

  5. Update the application.properties under src/main/resources with the credentials you get in the above step and your Azure Spring Apps instance.

    eureka.client.serviceUrl.defaultZone=https://<service name>.svc.asc-test.net/eureka/eureka
    access.token.clientId=<appId>
    access.token.secret=<password>
    access.token.tenantId=<tenant>
  6. Package the app using maven and run it locally

    mvn clean package -D skipTests
    mvn spring-boot:run
  7. You can query the apps which register to the eureka server by app name

    curl http://127.0.0.1:8080/TEST
    [{"port":8080,"host":"host.docker.internal","scheme":"http","metadata":{"management.port":"8080"},"secure":false,"instanceId":"host.docker.internal:test","serviceId":"TEST","instanceInfo":{"instanceId":"host.docker.internal:test","app":"TEST","appGroupName":null,"ipAddr":"x.x.x.x","sid":"na","homePageUrl":"http://host.docker.internal:8080/","statusPageUrl":"http://host.docker.internal:8080/actuator/info","healthCheckUrl":"http://host.docker.internal:8080/actuator/health","secureHealthCheckUrl":null,"vipAddress":"test","secureVipAddress":"test","countryId":1,"dataCenterInfo":{"@class":"com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo","name":"MyOwn"},"hostName":"host.docker.internal","status":"UP","overriddenStatus":"UNKNOWN","leaseInfo":{"renewalIntervalInSecs":30,"durationInSecs":90,"registrationTimestamp":xxxxxxx,"lastRenewalTimestamp":xxxxxxxx,"evictionTimestamp":0,"serviceUpTimestamp":xxxxxxxx},"isCoordinatingDiscoveryServer":false,"metadata":{"management.port":"8080"},"lastUpdatedTimestamp":xxxxxxxx,"lastDirtyTimestamp":xxxxxxxx,"actionType":"ADDED","asgName":null},"uri":"http://host.docker.internal:8080"}]%