Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OTSWithFeign
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Siva Naga Someswara Jatla
OTSWithFeign
Commits
c1f321e7
Commit
c1f321e7
authored
May 05, 2020
by
sgandhi@nisum.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added feign client and ribbon load balancing to both pe and ots
parent
b024c903
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
105 additions
and
11 deletions
+105
-11
build.gradle
build.gradle
+18
-3
OffertransactionserviceApplication.java
...ransactionservice/OffertransactionserviceApplication.java
+4
-0
ClientService.java
...m/nisum/offertransactionservice/client/ClientService.java
+0
-2
FeignClientService.java
...um/offertransactionservice/client/FeignClientService.java
+15
-0
CustomErrorDecoder.java
...um/offertransactionservice/config/CustomErrorDecoder.java
+25
-0
FeignClientConfiguration.java
...ertransactionservice/config/FeignClientConfiguration.java
+18
-0
OfferLookupRepo.java
...om/nisum/offertransactionservice/dao/OfferLookupRepo.java
+3
-0
OfferCallingPEService.java
...ffertransactionservice/service/OfferCallingPEService.java
+15
-4
ExceptionUtil.java
...com/nisum/offertransactionservice/util/ExceptionUtil.java
+1
-0
application.properties
src/main/resources/application.properties
+6
-2
No files found.
build.gradle
View file @
c1f321e7
plugins
{
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
'io.spring.dependency-management'
version
'1.0.9.RELEASE'
id
'java'
id
'java'
id
'net.ltgt.apt'
version
'0.20'
id
'net.ltgt.apt'
version
'0.20'
...
@@ -19,15 +19,22 @@ configurations {
...
@@ -19,15 +19,22 @@ configurations {
repositories
{
repositories
{
flatDir
{
flatDir
{
dirs
'/Users/sivanaga
gandhi
someswaragandhijatla/.m2/repository/com/nisum/exceptionservice/0.0.1'
dirs
'/Users/sivanagasomeswaragandhijatla/.m2/repository/com/nisum/exceptionservice/0.0.1'
// dirs '/Users/sivanagaga
ndhi
someswaragandhijatla/.m2/repository/com/nisum/exceptionservice/0.0.1'
// dirs '/Users/sivanagagasomeswaragandhijatla/.m2/repository/com/nisum/exceptionservice/0.0.1'
}
}
mavenCentral
()
mavenCentral
()
}
}
ext
{
set
(
'springCloudVersion'
,
"Hoxton.SR4"
)
}
dependencies
{
dependencies
{
//TODO: Make it
//TODO: Make it
compile
'org.mapstruct:mapstruct:1.3.1.Final'
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'
annotationProcessor
'org.mapstruct:mapstruct-processor:1.3.1.Final'
implementation
'org.springframework.boot:spring-boot-starter-web'
implementation
'org.springframework.boot:spring-boot-starter-web'
implementation
'org.springframework.boot:spring-boot-starter-webflux'
implementation
'org.springframework.boot:spring-boot-starter-webflux'
...
@@ -56,7 +63,15 @@ dependencies {
...
@@ -56,7 +63,15 @@ dependencies {
testCompile
group:
'org.springframework.cloud'
,
name:
'spring-cloud-starter-contract-stub-runner'
,
version:
'2.2.2.RELEASE'
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
{
test
{
useJUnitPlatform
()
useJUnitPlatform
()
}
}
src/main/java/com/nisum/offertransactionservice/OffertransactionserviceApplication.java
View file @
c1f321e7
...
@@ -3,9 +3,13 @@ package com.nisum.offertransactionservice;
...
@@ -3,9 +3,13 @@ package com.nisum.offertransactionservice;
import
com.safeway.epe.exception.ExceptionResponseHandlerImpl
;
import
com.safeway.epe.exception.ExceptionResponseHandlerImpl
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
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
;
import
org.springframework.context.annotation.Bean
;
@SpringBootApplication
@SpringBootApplication
@EnableFeignClients
@EnableDiscoveryClient
public
class
OffertransactionserviceApplication
{
public
class
OffertransactionserviceApplication
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
...
...
src/main/java/com/nisum/offertransactionservice/client/ClientService.java
View file @
c1f321e7
...
@@ -16,8 +16,6 @@ import reactor.core.publisher.Mono;
...
@@ -16,8 +16,6 @@ import reactor.core.publisher.Mono;
import
javax.annotation.PostConstruct
;
import
javax.annotation.PostConstruct
;
import
static
com
.
nisum
.
offertransactionservice
.
util
.
ExceptionUtil
.
handleError
;
@Component
@Component
@Slf4j
@Slf4j
public
class
ClientService
{
public
class
ClientService
{
...
...
src/main/java/com/nisum/offertransactionservice/client/FeignClientService.java
0 → 100644
View file @
c1f321e7
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
);
}
src/main/java/com/nisum/offertransactionservice/config/CustomErrorDecoder.java
0 → 100644
View file @
c1f321e7
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
);
}
}
src/main/java/com/nisum/offertransactionservice/config/FeignClientConfiguration.java
0 → 100644
View file @
c1f321e7
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
src/main/java/com/nisum/offertransactionservice/dao/OfferLookupRepo.java
View file @
c1f321e7
...
@@ -10,6 +10,9 @@ import java.util.List;
...
@@ -10,6 +10,9 @@ import java.util.List;
public
interface
OfferLookupRepo
extends
JpaRepository
<
OfferLookup
,
String
>
{
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
)
@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
);
public
List
<
OfferLookup
>
findByHhId
(
@Param
(
"ids"
)
Collection
<
String
>
ids
,
@Param
(
"offerType"
)
String
offerType
);
...
...
src/main/java/com/nisum/offertransactionservice/service/OfferCallingPEService.java
View file @
c1f321e7
...
@@ -2,17 +2,23 @@ package com.nisum.offertransactionservice.service;
...
@@ -2,17 +2,23 @@ package com.nisum.offertransactionservice.service;
import
com.nisum.offertransactionservice.client.ClientService
;
import
com.nisum.offertransactionservice.client.ClientService
;
import
com.nisum.offertransactionservice.client.FeignClientService
;
import
com.nisum.offertransactionservice.converter.OfferConvertion
;
import
com.nisum.offertransactionservice.converter.OfferConvertion
;
import
com.nisum.offertransactionservice.dao.OfferLookupRepo
;
import
com.nisum.offertransactionservice.dao.OfferLookupRepo
;
import
com.nisum.offertransactionservice.dao.OfferMetaDataRepo
;
import
com.nisum.offertransactionservice.dao.OfferMetaDataRepo
;
import
com.nisum.offertransactionservice.dto.*
;
import
com.nisum.offertransactionservice.dto.*
;
import
com.nisum.offertransactionservice.genericexception.GlobalApiGenericException
;
import
com.nisum.offertransactionservice.genericexception.GlobalApiGenericException
;
import
com.nisum.offertransactionservice.model.*
;
import
com.nisum.offertransactionservice.model.*
;
import
com.nisum.offertransactionservice.util.ExceptionUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.mapstruct.factory.Mappers
;
import
org.mapstruct.factory.Mappers
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.PropertySource
;
import
org.springframework.context.annotation.PropertySource
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.reactive.function.client.ClientResponse
;
import
reactor.core.publisher.Flux
;
import
javax.validation.constraints.NotNull
;
import
javax.validation.constraints.NotNull
;
import
java.util.*
;
import
java.util.*
;
...
@@ -25,6 +31,9 @@ public class OfferCallingPEService {
...
@@ -25,6 +31,9 @@ public class OfferCallingPEService {
OfferConvertion
INSTANCE
=
Mappers
.
getMapper
(
OfferConvertion
.
class
);
OfferConvertion
INSTANCE
=
Mappers
.
getMapper
(
OfferConvertion
.
class
);
@Autowired
private
FeignClientService
feignClientService
;
@Autowired
@Autowired
private
OfferLookupRepo
offerLookupRepo
;
private
OfferLookupRepo
offerLookupRepo
;
...
@@ -49,10 +58,12 @@ public class OfferCallingPEService {
...
@@ -49,10 +58,12 @@ public class OfferCallingPEService {
OfferTransactionResponse
offerTransactionResponse
;
OfferTransactionResponse
offerTransactionResponse
;
PERequest
peRequest
=
INSTANCE
.
map
(
offerTransactionRequest
);
PERequest
peRequest
=
INSTANCE
.
map
(
offerTransactionRequest
);
peRequest
.
setEligibleOffers
(
offerLookupDTOList
);
peRequest
.
setEligibleOffers
(
offerLookupDTOList
);
log
.
info
(
"Promotional Engine WebClient call Start"
);
log
.
info
(
"Promotional Engine Feign client call Start"
);
PEResponse
peResponseFlux
=
clientService
.
getPeResponseFlux
(
peRequest
);
/*PEResponse peResponseFlux = clientService.getPeResponseFlux(peRequest);*/
log
.
debug
(
"Promotional Engine WebClient call End"
);
ResponseEntity
<
PEResponse
>
peResponseFlux
=
feignClientService
.
callPEService
(
peRequest
);
offerTransactionResponse
=
INSTANCE
.
map
(
peResponseFlux
);
log
.
debug
(
"Promotional Engine Feign client call End"
);
offerTransactionResponse
=
INSTANCE
.
map
(
peResponseFlux
.
getBody
());
offerTransactionResponse
.
setTransactionId
(
offerTransactionRequest
.
getTransactionId
());
offerTransactionResponse
.
setTransactionId
(
offerTransactionRequest
.
getTransactionId
());
log
.
debug
(
"Offer Transaction Response {}"
,
offerTransactionResponse
);
log
.
debug
(
"Offer Transaction Response {}"
,
offerTransactionResponse
);
return
offerTransactionResponse
;
return
offerTransactionResponse
;
...
...
src/main/java/com/nisum/offertransactionservice/util/ExceptionUtil.java
View file @
c1f321e7
...
@@ -23,4 +23,5 @@ public class ExceptionUtil {
...
@@ -23,4 +23,5 @@ public class ExceptionUtil {
log
.
error
(
"Error Response While Calling Service {}"
,
response
);
log
.
error
(
"Error Response While Calling Service {}"
,
response
);
throw
new
GlobalApiGenericException
(
response
,
response
.
getHttpStatusCode
());
throw
new
GlobalApiGenericException
(
response
,
response
.
getHttpStatusCode
());
}
}
}
}
src/main/resources/application.properties
View file @
c1f321e7
...
@@ -2,7 +2,11 @@ spring.datasource.url=jdbc:postgresql://127.0.0.1:5432/storedb
...
@@ -2,7 +2,11 @@ spring.datasource.url=jdbc:postgresql://127.0.0.1:5432/storedb
spring.datasource.username
=
postgres
spring.datasource.username
=
postgres
spring.datasource.password
=
dbpwd
spring.datasource.password
=
dbpwd
endpoint.url.promotionEngineUrl
=
/promotionEngine/calculateDiscount
endpoint.url.promotionEngineUrl
=
/promotionEngine/calculateDiscount
endpoint.url.peBaseUrl
=
http://localhost:7073
pe.application.name
=
pe
endpoint.url.storeProducerUrl
=
/store/producer
endpoint.url.storeProducerUrl
=
/store/producer
endpoint.url.spBaseUrl
=
http://localhost:7070
endpoint.url.spBaseUrl
=
http://localhost:7070
server.port
=
7072
server.port
=
7072
\ No newline at end of file
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment