Commit c1f321e7 authored by sgandhi@nisum.com's avatar sgandhi@nisum.com

added feign client and ribbon load balancing to both pe and ots

parent b024c903
plugins {
id 'org.springframework.boot' version '2.2.5.RELEASE'
id 'org.springframework.boot' version '2.2.6.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
id 'net.ltgt.apt' version '0.20'
......@@ -19,15 +19,22 @@ configurations {
repositories {
flatDir {
dirs '/Users/sivanagagandhisomeswaragandhijatla/.m2/repository/com/nisum/exceptionservice/0.0.1'
// dirs '/Users/sivanagagandhisomeswaragandhijatla/.m2/repository/com/nisum/exceptionservice/0.0.1'
dirs '/Users/sivanagasomeswaragandhijatla/.m2/repository/com/nisum/exceptionservice/0.0.1'
// dirs '/Users/sivanagagasomeswaragandhijatla/.m2/repository/com/nisum/exceptionservice/0.0.1'
}
mavenCentral()
}
ext {
set('springCloudVersion', "Hoxton.SR4")
}
dependencies {
//TODO: Make it
compile 'org.mapstruct:mapstruct:1.3.1.Final'
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.3.1.Final'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
......@@ -56,7 +63,15 @@ dependencies {
testCompile group: 'org.springframework.cloud', name: 'spring-cloud-starter-contract-stub-runner', version: '2.2.2.RELEASE'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
test {
useJUnitPlatform()
}
......@@ -3,9 +3,13 @@ package com.nisum.offertransactionservice;
import com.safeway.epe.exception.ExceptionResponseHandlerImpl;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
@EnableFeignClients
@EnableDiscoveryClient
public class OffertransactionserviceApplication {
public static void main(String[] args) {
......
......@@ -16,8 +16,6 @@ import reactor.core.publisher.Mono;
import javax.annotation.PostConstruct;
import static com.nisum.offertransactionservice.util.ExceptionUtil.handleError;
@Component
@Slf4j
public class ClientService {
......
package com.nisum.offertransactionservice.client;
import com.nisum.offertransactionservice.config.FeignClientConfiguration;
import com.nisum.offertransactionservice.dto.PERequest;
import com.nisum.offertransactionservice.dto.PEResponse;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
@FeignClient(name = "${pe.application.name}", configuration = FeignClientConfiguration.class)
public interface FeignClientService {
@PostMapping(value = "${endpoint.url.promotionEngineUrl}")
ResponseEntity<PEResponse> callPEService(PERequest peRequest);
}
package com.nisum.offertransactionservice.config;
import com.nisum.offertransactionservice.genericexception.GlobalApiGenericException;
import feign.Response;
import feign.codec.ErrorDecoder;
public class CustomErrorDecoder implements ErrorDecoder {
@Override
public Exception decode(String methodKey, Response response) {
String httpStatusDesc = null;
switch (response.status()) {
case 400:
httpStatusDesc = "Bad Request";
break;
case 404:
httpStatusDesc = "Not found";
break;
case 500:
httpStatusDesc = "Internal Error";
break;
default:
httpStatusDesc = "Generic error";
}
return new GlobalApiGenericException(Integer.toString(response.status()), true, null);
}
}
package com.nisum.offertransactionservice.config;
import feign.Logger;
import feign.codec.ErrorDecoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class FeignClientConfiguration {
@Bean
public Logger.Level feignLoggerLevel() {
return Logger.Level.FULL;
}
@Bean
public ErrorDecoder errorDecoder() {
return new CustomErrorDecoder();
}
}
\ No newline at end of file
......@@ -10,6 +10,9 @@ import java.util.List;
public interface OfferLookupRepo extends JpaRepository<OfferLookup,String> {
/* @Query(value= "SELECT * FROM offer_lookup WHERE id in :ids and UPPER(offer_type) = UPPER(:offerType)" , nativeQuery = true)
public List<OfferLookup> findByHhId(@Param("ids") Collection<String> ids, @Param("offerType") String offerType);*/
@Query(value= "SELECT * FROM offer_lookup WHERE id in :ids and UPPER(offer_type) = UPPER(:offerType)" , nativeQuery = true)
public List<OfferLookup> findByHhId(@Param("ids") Collection<String> ids, @Param("offerType") String offerType);
......
......@@ -2,17 +2,23 @@ package com.nisum.offertransactionservice.service;
import com.nisum.offertransactionservice.client.ClientService;
import com.nisum.offertransactionservice.client.FeignClientService;
import com.nisum.offertransactionservice.converter.OfferConvertion;
import com.nisum.offertransactionservice.dao.OfferLookupRepo;
import com.nisum.offertransactionservice.dao.OfferMetaDataRepo;
import com.nisum.offertransactionservice.dto.*;
import com.nisum.offertransactionservice.genericexception.GlobalApiGenericException;
import com.nisum.offertransactionservice.model.*;
import com.nisum.offertransactionservice.util.ExceptionUtil;
import lombok.extern.slf4j.Slf4j;
import org.mapstruct.factory.Mappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.PropertySource;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.ClientResponse;
import reactor.core.publisher.Flux;
import javax.validation.constraints.NotNull;
import java.util.*;
......@@ -25,6 +31,9 @@ public class OfferCallingPEService {
OfferConvertion INSTANCE = Mappers.getMapper(OfferConvertion.class);
@Autowired
private FeignClientService feignClientService;
@Autowired
private OfferLookupRepo offerLookupRepo;
......@@ -49,10 +58,12 @@ public class OfferCallingPEService {
OfferTransactionResponse offerTransactionResponse;
PERequest peRequest = INSTANCE.map(offerTransactionRequest);
peRequest.setEligibleOffers(offerLookupDTOList);
log.info("Promotional Engine WebClient call Start");
PEResponse peResponseFlux = clientService.getPeResponseFlux(peRequest);
log.debug("Promotional Engine WebClient call End");
offerTransactionResponse = INSTANCE.map(peResponseFlux);
log.info("Promotional Engine Feign client call Start");
/*PEResponse peResponseFlux = clientService.getPeResponseFlux(peRequest);*/
ResponseEntity<PEResponse> peResponseFlux = feignClientService.callPEService(peRequest);
log.debug("Promotional Engine Feign client call End");
offerTransactionResponse = INSTANCE.map(peResponseFlux.getBody());
offerTransactionResponse.setTransactionId(offerTransactionRequest.getTransactionId());
log.debug("Offer Transaction Response {}", offerTransactionResponse);
return offerTransactionResponse;
......
......@@ -23,4 +23,5 @@ public class ExceptionUtil {
log.error("Error Response While Calling Service {}", response);
throw new GlobalApiGenericException(response, response.getHttpStatusCode());
}
}
......@@ -2,7 +2,11 @@ spring.datasource.url=jdbc:postgresql://127.0.0.1:5432/storedb
spring.datasource.username=postgres
spring.datasource.password=dbpwd
endpoint.url.promotionEngineUrl=/promotionEngine/calculateDiscount
endpoint.url.peBaseUrl=http://localhost:7073
pe.application.name=pe
endpoint.url.storeProducerUrl=/store/producer
endpoint.url.spBaseUrl=http://localhost:7070
server.port = 7072
spring.application.name=ots
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.show-sql=true
\ No newline at end of file
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