Skip to content

Commit

Permalink
Step23
Browse files Browse the repository at this point in the history
  • Loading branch information
Ranga Rao Karanam authored and Ranga Rao Karanam committed Sep 9, 2017
1 parent 928200e commit 9d9124f
Show file tree
Hide file tree
Showing 7 changed files with 1,164 additions and 14 deletions.
11 changes: 11 additions & 0 deletions 03.microservices/currency-conversion-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
</dependency>

<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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -12,26 +13,37 @@

@RestController
public class CurrencyConversionController {


@Autowired
private CurrencyExchangeServiceProxy proxy;

@GetMapping("/currency-converter/from/{from}/to/{to}/quantity/{quantity}")
public CurrencyConversionBean convertCurrency(@PathVariable String from,
@PathVariable String to,
@PathVariable BigDecimal quantity
){

public CurrencyConversionBean convertCurrency(@PathVariable String from, @PathVariable String to,
@PathVariable BigDecimal quantity) {

// Feign - Problem 1
Map<String, String> uriVariables = new HashMap<>();
uriVariables.put("from", from);
uriVariables.put("to", to);

ResponseEntity<CurrencyConversionBean> responseEntity = new RestTemplate().getForEntity(
"http://localhost:8000/currency-exchange/from/{from}/to/{to}",
CurrencyConversionBean.class,
uriVariables );

"http://localhost:8000/currency-exchange/from/{from}/to/{to}", CurrencyConversionBean.class,
uriVariables);

CurrencyConversionBean response = responseEntity.getBody();

return new CurrencyConversionBean(response.getId(),from,to,response.getConversionMultiple(),
quantity,quantity.multiply(response.getConversionMultiple()),response.getPort());

return new CurrencyConversionBean(response.getId(), from, to, response.getConversionMultiple(), quantity,
quantity.multiply(response.getConversionMultiple()), response.getPort());
}

@GetMapping("/currency-converter-feign/from/{from}/to/{to}/quantity/{quantity}")
public CurrencyConversionBean convertCurrencyFeign(@PathVariable String from, @PathVariable String to,
@PathVariable BigDecimal quantity) {

CurrencyConversionBean response = proxy.retrieveExchangeValue(from, to);

return new CurrencyConversionBean(response.getId(), from, to, response.getConversionMultiple(), quantity,
quantity.multiply(response.getConversionMultiple()), response.getPort());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.feign.EnableFeignClients;

@SpringBootApplication
@EnableFeignClients("com.in28minutes.microservices.currencyconversionservice")
public class CurrencyConversionServiceApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.in28minutes.microservices.currencyconversionservice;

import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

//@FeignClient(name="currency-exchange-service", url="localhost:8000")
@FeignClient(name="currency-exchange-service")
@RibbonClient(name="currency-exchange-service")
public interface CurrencyExchangeServiceProxy {
@GetMapping("/currency-exchange/from/{from}/to/{to}")
public CurrencyConversionBean retrieveExchangeValue
(@PathVariable("from") String from, @PathVariable("to") String to);
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
spring.application.name=currency-conversion-service
server.port=8100
server.port=8100
currency-exchange-service.ribbon.listOfServers=http://localhost:8000,http://localhost:8001
Loading

0 comments on commit 9d9124f

Please sign in to comment.