Skip to content

Commit

Permalink
Add java 17 sample
Browse files Browse the repository at this point in the history
  • Loading branch information
dingmeng-xue committed Sep 18, 2024
1 parent fa7f0ff commit 9338ef5
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 63 deletions.
5 changes: 1 addition & 4 deletions config-server-yaml-samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,4 @@ The more complex like pattern matching on the application and profile name is al

### Reference

1. https://cloud.spring.io/spring-cloud-static/spring-cloud-config/2.1.4.RELEASE/single/spring-cloud-config.html#_git_backend
2. https://cloud.spring.io/spring-cloud-static/spring-cloud-config/2.1.4.RELEASE/single/spring-cloud-config.html#_authentication
3. https://cloud.spring.io/spring-cloud-static/spring-cloud-config/2.1.4.RELEASE/single/spring-cloud-config.html#_git_ssh_configuration_using_properties
4. https://cloud.spring.io/spring-cloud-static/spring-cloud-config/2.1.4.RELEASE/single/spring-cloud-config.html#_pattern_matching_and_multiple_repositories
1. https://docs.spring.io/spring-cloud-config/reference/server/environment-repository/git-backend.html
38 changes: 0 additions & 38 deletions java-17-sample/.gitignore

This file was deleted.

20 changes: 10 additions & 10 deletions java-17-sample/README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
# Local Development

```shell
docker run --rm -p 8761:8761 springcloud/demo-eureka-server
```

# Prepare Variables
```shell
SUBSCRIPTION=6c933f90-8115-4392-90f2-7077c9fa5dbd
LOCATION=westus2
RESOURCE_GROUP=dixue-asas-vnet-prod
SERVICE_NAME=dixue-asas-vnet-prod
SUBSCRIPTION=
LOCATION=
RESOURCE_GROUP=
SERVICE_NAME=

az account set --subscription $SUBSCRIPTION
```

# Standard Plan
## Provision ASA Service Instance
```shell

```
## Deploy Application
```shell
mvn clean package
az spring app create -n java17sample --service $SERVICE_NAME -g $RESOURCE_GROUP --runtime-version Java_17 --assign-endpoint true
az spring app deploy -n java17sample --service $SERVICE_NAME -g $RESOURCE_GROUP --artifact-path ./target/java-17-sample-1.0-SNAPSHOT.jar
```
# Enterprise Plan
## Provision ASA Service Instance

## Deploy Application
34 changes: 26 additions & 8 deletions java-17-sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,10 @@
<artifactId>java-17-sample</artifactId>
<version>1.0-SNAPSHOT</version>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.2</version>
</parent>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring-cloud.version>2023.0.3</spring-cloud.version>
</properties>

<dependencies>
Expand All @@ -42,14 +35,31 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.14</version>
</dependency>
<dependency>
<groupId>com.fasterxml.woodstox</groupId>
<artifactId>woodstox-core</artifactId>
<version>6.4.0</version>
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>3.3.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<version>2023.0.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand All @@ -61,6 +71,14 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>3.3.3</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.azure.asa.sample;

import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.EurekaClient;
import com.netflix.discovery.shared.Application;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Set;

@RestController
public class EurekaController {

@Autowired
private EurekaClient discoveryClient;

@GetMapping("/eureka")
public String getEurekaState() {
StringBuilder sb = new StringBuilder();

sb.append("<p>Known Regions</p>");
sb.append("<ul>");
Set<String> regions = discoveryClient.getAllKnownRegions();
for(String region : regions) {
sb.append("<li>").append(region).append("</li>");
}
sb.append("</ul>");

List<Application> apps = discoveryClient.getApplications().getRegisteredApplications();
sb.append("<p>Registered Applications</p>");
sb.append("<ul>");
for(Application app : apps) {
sb.append("<p>Application=").append(app.getName()).append("</p>");
sb.append("<ul>");
List<InstanceInfo> instances = app.getInstances();
for(InstanceInfo instance : instances) {
sb.append("<ul>");
sb.append("<li>InstanceId=").append(instance.getInstanceId()).append("</li>");
sb.append("<li>Status=").append(instance.getStatus().toString()).append("</li>");
sb.append("<li>IPAddr=").append(instance.getIPAddr()).append("</li>");
sb.append("</ul>");
}
sb.append("</ul>");
}
sb.append("</ul>");

sb.append("<p>Client Configuration</p>");
sb.append("<ul>").append(discoveryClient.getEurekaClientConfig().toString()).append("</ul>");

return sb.toString();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.azure.asa.sample;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -13,7 +12,7 @@ public class HelloController {

@GetMapping("/")
public String index() {
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
sb.append("<h1>Greetings from Spring Boot!</h1>");

return sb.toString();
Expand Down
6 changes: 5 additions & 1 deletion java-17-sample/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
spring.application.name=java-17-sample
management.endpoints.web.exposure.include=*
management.endpoint.env.show-values=ALWAYS
management.endpoint.env.show-values=ALWAYS
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
eureka.client.healthcheck.enabled=true
spring.cloud.config.enabled=false

0 comments on commit 9338ef5

Please sign in to comment.