Skip to content

Commit 4785a24

Browse files
authored
BAEL-5266: Netflix sidecar demo applications created. (#12183)
* BAEL-5266: Netflix sidecar demo applications created. * BAEL-5266: Changed NodeJS endpoint to hello * BAEL-5266: Removed .gitignore files as the .gitignore is already available in project scope.
1 parent a1e7799 commit 4785a24

10 files changed

Lines changed: 260 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<artifactId>echo-demo</artifactId>
6+
<name>echo-demo</name>
7+
<description>Demo for echo endpoint</description>
8+
<parent>
9+
<groupId>com.baeldung.cloud</groupId>
10+
<artifactId>spring-cloud-netflix-sidecar</artifactId>
11+
<version>0.0.1-SNAPSHOT</version>
12+
<relativePath>../pom.xml</relativePath>
13+
</parent>
14+
<dependencies>
15+
<dependency>
16+
<groupId>org.springframework.boot</groupId>
17+
<artifactId>spring-boot-starter-actuator</artifactId>
18+
</dependency>
19+
<dependency>
20+
<groupId>org.springframework.boot</groupId>
21+
<artifactId>spring-boot-starter-web</artifactId>
22+
</dependency>
23+
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-netflix-zuul -->
24+
<dependency>
25+
<groupId>org.springframework.cloud</groupId>
26+
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
27+
<version>2.2.10.RELEASE</version>
28+
</dependency>
29+
<dependency>
30+
<groupId>org.springframework.cloud</groupId>
31+
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
32+
<version>2.2.10.RELEASE</version>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.springframework.boot</groupId>
36+
<artifactId>spring-boot-starter-test</artifactId>
37+
<scope>test</scope>
38+
</dependency>
39+
</dependencies>
40+
<build>
41+
<plugins>
42+
<plugin>
43+
<groupId>org.springframework.boot</groupId>
44+
<artifactId>spring-boot-maven-plugin</artifactId>
45+
</plugin>
46+
</plugins>
47+
</build>
48+
</project>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.baeldung.cloud.echo;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.boot.SpringApplication;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
import org.springframework.cloud.client.ServiceInstance;
7+
import org.springframework.cloud.client.discovery.DiscoveryClient;
8+
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
9+
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
10+
import org.springframework.context.annotation.Bean;
11+
import org.springframework.http.HttpStatus;
12+
import org.springframework.http.ResponseEntity;
13+
import org.springframework.web.bind.annotation.GetMapping;
14+
import org.springframework.web.bind.annotation.PathVariable;
15+
import org.springframework.web.bind.annotation.RestController;
16+
import org.springframework.web.client.RestTemplate;
17+
18+
import java.util.List;
19+
20+
@SpringBootApplication
21+
@EnableEurekaClient
22+
@EnableZuulProxy
23+
@RestController
24+
public class EchoApplication {
25+
@Autowired
26+
DiscoveryClient discoveryClient;
27+
@Autowired
28+
RestTemplate restTemplate;
29+
30+
@Bean
31+
public RestTemplate restTemplate() {
32+
return new RestTemplate();
33+
}
34+
35+
@GetMapping("/hello/{me}")
36+
public ResponseEntity<String> echo(@PathVariable("me") String me) {
37+
List<ServiceInstance> instances = discoveryClient.getInstances("sidecar");
38+
if (instances.isEmpty()) {
39+
return ResponseEntity.status(HttpStatus.SERVICE_UNAVAILABLE).body("hello service is down");
40+
}
41+
String url = instances.get(0).getUri().toString();
42+
return ResponseEntity.ok(restTemplate.getForObject(url + "/hello/" + me, String.class));
43+
}
44+
45+
public static void main(String[] args) {
46+
SpringApplication.run(EchoApplication.class, args);
47+
}
48+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
server.port: 8085
2+
spring:
3+
application:
4+
name: echo
5+
eureka:
6+
instance:
7+
hostname: localhost
8+
leaseRenewalIntervalInSeconds: 1
9+
leaseExpirationDurationInSeconds: 2
10+
client:
11+
service-url:
12+
defaultZone: http://127.0.0.1:8761/eureka
13+
healthcheck:
14+
enabled: true
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.baeldung.cloud.echo;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.springframework.boot.test.context.SpringBootTest;
5+
6+
@SpringBootTest
7+
public class SpringContextTest {
8+
@Test
9+
void contextLoads() {
10+
}
11+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<groupId>com.baeldung.cloud</groupId>
7+
<artifactId>spring-cloud-netflix-sidecar</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>pom</packaging>
10+
<name>spring-cloud-netflix-sidecar</name>
11+
<description>Netflix Sidecar project for Spring Boot</description>
12+
13+
<parent>
14+
<groupId>com.baeldung</groupId>
15+
<artifactId>parent-boot-2</artifactId>
16+
<version>0.0.1-SNAPSHOT</version>
17+
<relativePath>../../parent-boot-2</relativePath>
18+
</parent>
19+
<modules>
20+
<module>sidecar-demo</module>
21+
<module>echo-demo</module>
22+
</modules>
23+
<properties>
24+
<netflix.cloud.version>2.2.10.RELEASE</netflix.cloud.version>
25+
<spring-boot.version>2.3.12.RELEASE</spring-boot.version>
26+
</properties>
27+
</project>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const express = require('express')
2+
const app = express()
3+
const port = 3000
4+
5+
app.get('/', (req, res) => {
6+
res.send('Hello World!')
7+
})
8+
9+
app.get('/health', (req, res) => {
10+
res.send({ "status":"UP"})
11+
})
12+
13+
app.get('/hello/:me', (req, res) => {
14+
res.send('Hello ' + req.params.me + '!')
15+
})
16+
17+
app.listen(port, () => {
18+
console.log(`Hello app listening on port ${port}`)
19+
})
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<artifactId>sidecar-demo</artifactId>
6+
<name>sidecar-demo</name>
7+
<description>Sidecar demo for hello endpoint</description>
8+
<parent>
9+
<groupId>com.baeldung.cloud</groupId>
10+
<artifactId>spring-cloud-netflix-sidecar</artifactId>
11+
<version>0.0.1-SNAPSHOT</version>
12+
<relativePath>../pom.xml</relativePath>
13+
</parent>
14+
<dependencies>
15+
<dependency>
16+
<groupId>org.springframework.boot</groupId>
17+
<artifactId>spring-boot-starter-actuator</artifactId>
18+
</dependency>
19+
<dependency>
20+
<groupId>org.springframework.cloud</groupId>
21+
<artifactId>spring-cloud-netflix-sidecar</artifactId>
22+
<version>${netflix.cloud.version}</version>
23+
</dependency>
24+
<dependency>
25+
<groupId>io.projectreactor</groupId>
26+
<artifactId>reactor-core</artifactId>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.springframework.boot</groupId>
30+
<artifactId>spring-boot-starter-test</artifactId>
31+
<scope>test</scope>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.junit.jupiter</groupId>
35+
<artifactId>junit-jupiter</artifactId>
36+
<scope>test</scope>
37+
</dependency>
38+
<dependency>
39+
<groupId>org.mockito</groupId>
40+
<artifactId>mockito-junit-jupiter</artifactId>
41+
<scope>test</scope>
42+
</dependency>
43+
</dependencies>
44+
<build>
45+
<plugins>
46+
<plugin>
47+
<groupId>org.springframework.boot</groupId>
48+
<artifactId>spring-boot-maven-plugin</artifactId>
49+
</plugin>
50+
</plugins>
51+
</build>
52+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.baeldung.cloud.sidecar;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.cloud.netflix.sidecar.EnableSidecar;
6+
7+
@SpringBootApplication
8+
@EnableSidecar
9+
public class SidecarApplication {
10+
public static void main(String[] args) {
11+
SpringApplication.run(SidecarApplication.class, args);
12+
}
13+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
server.port: 8084
2+
spring:
3+
application:
4+
name: sidecar
5+
eureka:
6+
instance:
7+
hostname: localhost
8+
leaseRenewalIntervalInSeconds: 1
9+
leaseExpirationDurationInSeconds: 2
10+
client:
11+
service-url:
12+
defaultZone: http://127.0.0.1:8761/eureka
13+
healthcheck:
14+
enabled: true
15+
sidecar:
16+
port: 3000
17+
health-uri: http://localhost:3000/health
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.baeldung.cloud.sidecar;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.springframework.boot.test.context.SpringBootTest;
5+
6+
@SpringBootTest
7+
public class SpringContextTest {
8+
@Test
9+
void contextLoads() {
10+
}
11+
}

0 commit comments

Comments
 (0)