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.
This commit is contained in:
parent
a1e77995a6
commit
4785a24795
|
@ -0,0 +1,48 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>echo-demo</artifactId>
|
||||
<name>echo-demo</name>
|
||||
<description>Demo for echo endpoint</description>
|
||||
<parent>
|
||||
<groupId>com.baeldung.cloud</groupId>
|
||||
<artifactId>spring-cloud-netflix-sidecar</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-netflix-zuul -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
|
||||
<version>2.2.10.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
|
||||
<version>2.2.10.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,48 @@
|
|||
package com.baeldung.cloud.echo;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
|
||||
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableEurekaClient
|
||||
@EnableZuulProxy
|
||||
@RestController
|
||||
public class EchoApplication {
|
||||
@Autowired
|
||||
DiscoveryClient discoveryClient;
|
||||
@Autowired
|
||||
RestTemplate restTemplate;
|
||||
|
||||
@Bean
|
||||
public RestTemplate restTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
|
||||
@GetMapping("/hello/{me}")
|
||||
public ResponseEntity<String> echo(@PathVariable("me") String me) {
|
||||
List<ServiceInstance> instances = discoveryClient.getInstances("sidecar");
|
||||
if (instances.isEmpty()) {
|
||||
return ResponseEntity.status(HttpStatus.SERVICE_UNAVAILABLE).body("hello service is down");
|
||||
}
|
||||
String url = instances.get(0).getUri().toString();
|
||||
return ResponseEntity.ok(restTemplate.getForObject(url + "/hello/" + me, String.class));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(EchoApplication.class, args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
server.port: 8085
|
||||
spring:
|
||||
application:
|
||||
name: echo
|
||||
eureka:
|
||||
instance:
|
||||
hostname: localhost
|
||||
leaseRenewalIntervalInSeconds: 1
|
||||
leaseExpirationDurationInSeconds: 2
|
||||
client:
|
||||
service-url:
|
||||
defaultZone: http://127.0.0.1:8761/eureka
|
||||
healthcheck:
|
||||
enabled: true
|
|
@ -0,0 +1,11 @@
|
|||
package com.baeldung.cloud.echo;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
public class SpringContextTest {
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung.cloud</groupId>
|
||||
<artifactId>spring-cloud-netflix-sidecar</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>spring-cloud-netflix-sidecar</name>
|
||||
<description>Netflix Sidecar project for Spring Boot</description>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-boot-2</relativePath>
|
||||
</parent>
|
||||
<modules>
|
||||
<module>sidecar-demo</module>
|
||||
<module>echo-demo</module>
|
||||
</modules>
|
||||
<properties>
|
||||
<netflix.cloud.version>2.2.10.RELEASE</netflix.cloud.version>
|
||||
<spring-boot.version>2.3.12.RELEASE</spring-boot.version>
|
||||
</properties>
|
||||
</project>
|
|
@ -0,0 +1,19 @@
|
|||
const express = require('express')
|
||||
const app = express()
|
||||
const port = 3000
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
res.send('Hello World!')
|
||||
})
|
||||
|
||||
app.get('/health', (req, res) => {
|
||||
res.send({ "status":"UP"})
|
||||
})
|
||||
|
||||
app.get('/hello/:me', (req, res) => {
|
||||
res.send('Hello ' + req.params.me + '!')
|
||||
})
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Hello app listening on port ${port}`)
|
||||
})
|
|
@ -0,0 +1,52 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>sidecar-demo</artifactId>
|
||||
<name>sidecar-demo</name>
|
||||
<description>Sidecar demo for hello endpoint</description>
|
||||
<parent>
|
||||
<groupId>com.baeldung.cloud</groupId>
|
||||
<artifactId>spring-cloud-netflix-sidecar</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-netflix-sidecar</artifactId>
|
||||
<version>${netflix.cloud.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.projectreactor</groupId>
|
||||
<artifactId>reactor-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-junit-jupiter</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,13 @@
|
|||
package com.baeldung.cloud.sidecar;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.netflix.sidecar.EnableSidecar;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableSidecar
|
||||
public class SidecarApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SidecarApplication.class, args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
server.port: 8084
|
||||
spring:
|
||||
application:
|
||||
name: sidecar
|
||||
eureka:
|
||||
instance:
|
||||
hostname: localhost
|
||||
leaseRenewalIntervalInSeconds: 1
|
||||
leaseExpirationDurationInSeconds: 2
|
||||
client:
|
||||
service-url:
|
||||
defaultZone: http://127.0.0.1:8761/eureka
|
||||
healthcheck:
|
||||
enabled: true
|
||||
sidecar:
|
||||
port: 3000
|
||||
health-uri: http://localhost:3000/health
|
|
@ -0,0 +1,11 @@
|
|||
package com.baeldung.cloud.sidecar;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
public class SpringContextTest {
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue