Commit 4936ad1d authored by Benjamin Wilms's avatar Benjamin Wilms

Prepare excercise eureka client

parent 5c42b3fb
......@@ -3,6 +3,7 @@ package de.codecentric.resilience.eureka;
import com.netflix.discovery.EurekaClient;
import com.netflix.discovery.shared.Application;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
......@@ -22,6 +23,7 @@ public class EurekaClientApp {
@RestController
class ServiceInstanceRestController {
@Qualifier("eurekaClient")
@Autowired
private EurekaClient eurekaClient;
......
package de.codecentric.resilience.eureka;
import org.springframework.cloud.client.ServiceInstance;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
* @author Benjamin Wilms
*/
public class EurekaResponse {
private List<String> services;
private List<ServiceInstance> serviceInstanceList;
public List<String> getServices() {
return services;
}
public void setServices(List<String> services) {
this.services = services;
}
public List<ServiceInstance> getServiceInstanceList() {
if(serviceInstanceList == null)
{
return new ArrayList<>();
}
return serviceInstanceList;
}
}
......@@ -21,14 +21,15 @@
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-ribbon</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
......
package de.codecentric.resilience.ribbon;
package de.codecentric.resilience.eureka;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
......@@ -16,22 +15,20 @@ import org.springframework.web.client.RestTemplate;
@RestController
public class GreetingClient {
@Bean
RestTemplate restTemplate() {
return new RestTemplate();
}
@Bean
RestTemplate restTemplate(){
return new RestTemplate();
}
@Autowired
RestTemplate restTemplate;
@RequestMapping("/hi")
public String hi(@RequestParam(value="name", defaultValue="Artaban") String name) {
String greeting = this.restTemplate.getForObject("http://localhost:8010/greeting", String.class);
return String.format("%s, %s!", greeting, name);
}
@RequestMapping("/hi")
public String hi(@RequestParam(value = "name", defaultValue = "Artaban") String name) {
String greeting = this.restTemplate().getForObject("http://service-name-from-eureka/greeting", String.class);
return String.format("%s, %s!", greeting, name);
}
public static void main(String[] args) {
SpringApplication.run(GreetingClient.class, args);
}
public static void main(String[] args) {
SpringApplication.run(GreetingClient.class, args);
}
}
\ No newline at end of file
package de.codecentric.resilience.ribbon;
import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
/**
* @author Benjamin Wilms
*/
public class SayHelloConfiguration {
@Autowired
IClientConfig ribbonClientConfig;
@Bean
public IPing ribbonPing(IClientConfig config) {
return new PingUrl();
}
@Bean
public IRule ribbonRule(IClientConfig config) {
return new RoundRobinRule();
}
}
say-hello:
ribbon:
eureka:
enabled: false
listOfServers: localhost:8010,localhost:9092,localhost:9999
ServerListRefreshInterval: 15000
security:
basic:
enabled: false
management:
security:
enabled: false
\ No newline at end of file
enabled: false
eureka:
client:
register-with-eureka: false
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment