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
a8c26f2f
Commit
a8c26f2f
authored
May 06, 2020
by
Amar Bogari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added code for retry feature with timeout exception cases
parent
75bcbd2c
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
100 additions
and
10 deletions
+100
-10
build.gradle
build.gradle
+1
-1
PromotionEngineFeignClient.java
...transactionservice/client/PromotionEngineFeignClient.java
+3
-2
CustomErrorDecoder.java
...um/offertransactionservice/config/CustomErrorDecoder.java
+26
-0
CustomRetryer.java
...m/nisum/offertransactionservice/config/CustomRetryer.java
+34
-0
FeignClientConfig.java
...sum/offertransactionservice/config/FeignClientConfig.java
+27
-0
OfferCallingPEService.java
...ffertransactionservice/service/OfferCallingPEService.java
+2
-6
application.properties
src/main/resources/application.properties
+7
-1
No files found.
build.gradle
View file @
a8c26f2f
...
@@ -19,7 +19,7 @@ configurations {
...
@@ -19,7 +19,7 @@ configurations {
repositories
{
repositories
{
flatDir
{
flatDir
{
dirs
'
/Users/sivanagasomeswaragandhijatla/.m2/repository/com/nisum/exceptionservice/
0.0.1'
dirs
'
C:\\Users\\abogari\\.m2\\repository\\com\\nisum\\exceptionservice\\
0.0.1'
// dirs '/Users/sivanagagasomeswaragandhijatla/.m2/repository/com/nisum/exceptionservice/0.0.1'
// dirs '/Users/sivanagagasomeswaragandhijatla/.m2/repository/com/nisum/exceptionservice/0.0.1'
}
}
mavenCentral
()
mavenCentral
()
...
...
src/main/java/com/nisum/offertransactionservice/client/
FeignClientService
.java
→
src/main/java/com/nisum/offertransactionservice/client/
PromotionEngineFeignClient
.java
View file @
a8c26f2f
package
com
.
nisum
.
offertransactionservice
.
client
;
package
com
.
nisum
.
offertransactionservice
.
client
;
import
com.nisum.offertransactionservice.config.FeignClientConfig
;
import
com.nisum.offertransactionservice.dto.PERequest
;
import
com.nisum.offertransactionservice.dto.PERequest
;
import
com.nisum.offertransactionservice.dto.PEResponse
;
import
com.nisum.offertransactionservice.dto.PEResponse
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
@FeignClient
(
name
=
"${pe.application.name}"
)
@FeignClient
(
name
=
"${pe.application.name}"
,
configuration
=
FeignClientConfig
.
class
)
public
interface
FeignClientService
{
public
interface
PromotionEngineFeignClient
{
@PostMapping
(
value
=
"${endpoint.url.promotionEngineUrl}"
)
@PostMapping
(
value
=
"${endpoint.url.promotionEngineUrl}"
)
ResponseEntity
<
PEResponse
>
callPEService
(
PERequest
peRequest
);
ResponseEntity
<
PEResponse
>
callPEService
(
PERequest
peRequest
);
...
...
src/main/java/com/nisum/offertransactionservice/config/CustomErrorDecoder.java
0 → 100644
View file @
a8c26f2f
package
com
.
nisum
.
offertransactionservice
.
config
;
import
feign.FeignException
;
import
feign.Request
;
import
feign.Response
;
import
feign.RetryableException
;
import
feign.codec.ErrorDecoder
;
import
org.springframework.http.HttpStatus
;
import
java.util.Date
;
public
class
CustomErrorDecoder
implements
ErrorDecoder
{
private
final
ErrorDecoder
defaultErrorDecoder
=
new
Default
();
@Override
public
Exception
decode
(
String
methodKey
,
Response
response
)
{
Exception
exception
=
defaultErrorDecoder
.
decode
(
methodKey
,
response
);
if
(
response
.
status
()
==
HttpStatus
.
REQUEST_TIMEOUT
.
value
()){
return
new
RetryableException
(
408
,
"408 error"
,
response
.
request
().
httpMethod
(),
new
Date
(),
response
.
request
());
}
return
exception
;
}
}
src/main/java/com/nisum/offertransactionservice/config/CustomRetryer.java
0 → 100644
View file @
a8c26f2f
package
com
.
nisum
.
offertransactionservice
.
config
;
import
feign.RetryableException
;
import
feign.Retryer
;
public
class
CustomRetryer
implements
Retryer
{
private
final
Integer
maxAttempts
;
private
final
Long
backoff
;
int
attempt
;
public
CustomRetryer
(
Long
backoff
,
Integer
maxAttempts
)
{
this
.
backoff
=
backoff
;
this
.
maxAttempts
=
maxAttempts
;
this
.
attempt
=
1
;
}
public
void
continueOrPropagate
(
RetryableException
e
)
{
if
(
attempt
++
>=
maxAttempts
)
{
throw
e
;
}
try
{
Thread
.
sleep
(
backoff
);
}
catch
(
InterruptedException
ignored
)
{
Thread
.
currentThread
().
interrupt
();
}
}
@Override
public
Retryer
clone
()
{
return
new
CustomRetryer
(
backoff
,
maxAttempts
);
}
}
src/main/java/com/nisum/offertransactionservice/config/FeignClientConfig.java
0 → 100644
View file @
a8c26f2f
package
com
.
nisum
.
offertransactionservice
.
config
;
import
feign.Retryer
;
import
feign.codec.ErrorDecoder
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
@Configuration
public
class
FeignClientConfig
{
@Value
(
"#{new Integer('${maxattempts}')}"
)
private
Integer
maxAttempts
;
@Value
(
"#{new Long('${backoff}')}"
)
private
Long
backoff
;
@Bean
public
Retryer
retryer
()
{
return
new
CustomRetryer
(
backoff
,
maxAttempts
);
}
@Bean
public
ErrorDecoder
errorDecoder
()
{
return
new
CustomErrorDecoder
();
}
}
\ No newline at end of file
src/main/java/com/nisum/offertransactionservice/service/OfferCallingPEService.java
View file @
a8c26f2f
...
@@ -2,23 +2,19 @@ package com.nisum.offertransactionservice.service;
...
@@ -2,23 +2,19 @@ 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.client.
PromotionEngineFeignClient
;
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.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.*
;
...
@@ -32,7 +28,7 @@ public class OfferCallingPEService {
...
@@ -32,7 +28,7 @@ public class OfferCallingPEService {
OfferConvertion
INSTANCE
=
Mappers
.
getMapper
(
OfferConvertion
.
class
);
OfferConvertion
INSTANCE
=
Mappers
.
getMapper
(
OfferConvertion
.
class
);
@Autowired
@Autowired
private
FeignClientService
feignClientService
;
private
PromotionEngineFeignClient
feignClientService
;
@Autowired
@Autowired
...
...
src/main/resources/application.properties
View file @
a8c26f2f
...
@@ -9,4 +9,10 @@ endpoint.url.spBaseUrl=http://localhost:7070
...
@@ -9,4 +9,10 @@ endpoint.url.spBaseUrl=http://localhost:7070
server.port
=
7072
server.port
=
7072
spring.application.name
=
ots
spring.application.name
=
ots
eureka.client.serviceUrl.defaultZone
=
http://localhost:8761/eureka
eureka.client.serviceUrl.defaultZone
=
http://localhost:8761/eureka
//
TODO
:
add refresh eureka endpoint properties
//
TODO
:
add refresh eureka endpoint properties
\ No newline at end of file
endpoints.restart.enabled
=
true
endpoints.shutdown.enabled
=
true
endpoints.health.sensitive
=
false
maxattempts
=
3
backoff
=
2000
\ 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