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.
-
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
-
Install Azure CLI extension for Azure Spring Apps
az extension add --name spring-cloud
-
Create an instance of Azure Spring Apps
az spring-cloud create -n <service name> -g <resource group name>
-
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.
-
Update the
application.properties
undersrc/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>
-
Package the app using maven and run it locally
mvn clean package -D skipTests mvn spring-boot:run
-
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"}]%