I have a spring-boot app which uses Declarative Feign Client
#ComponentScan
#EnableFeignClients
#EnableCircuitBreaker
#EnableDiscoveryClient
#EnableZuulProxy
#FeignClient(name = "${service-registry-name}", fallbackFactory = MyFallbackFactory.class, configuration = CommonFeignConfiguration.class)
public interface MyClient {
#RequestMapping(method = RequestMethod.GET, path = "/test/reference/data")
HttpEntity<String> getAllData();}
I have following application.yml
feign:
okhttp:
enabled: true
feign:
hystrix:
enabled: true
hystrix:
command:
MyClient#getAllData():
execution:
isolation:
thread:
timeoutInMilliseconds: 30000
hystrix:
command:
default:
execution:
timeout:
enabled: false
logging:
level:
project:
user:
MyClient: DEBUG
feign:
client:
config:
feign-name:
requestInterceptors: com.test.MyRequestHeaderProcessor
This spring-boot app works perfectly fine and when I debug the I could see that the timeout value of 30000 is properly applied.
The trouble starts when I use this code NOT as a standalone spring boot app but as a dependency jar into another project.
At this time, the timeout is always 1000, which is the default. I managed to override this as well. But despite of that, i get HystrixRunTimeException, Timeout with null.
I have feign.hystrix.enabled=true.
If I use feign.hystrix.enabled=false, I can see that my request doesnt time out but then the Fallback mechanism fails to work.
But, when I add URL attribute in FeignClient it works fine and does NOT timeout.I cannot rely on the URL attribute as this is coming from the cloud foundry service URL which can change.
Add below properties in Application.yml file.
feign:
client:
config:
default:
connectTimeout: 80000000
readTimeout: 80000000
Related
I have the following health management endpoints in my application.yml file
management:
endpoints:
health:
sensitive: false
web:
base-path: /
and I have an interceptor with the following code
class TestInterceptor {
TestInterceptor() {
matchAll()
}
boolean before() {
if (request.forwardURI?.endsWith('.json')) {
// ... some code
return false
}
true
}
}
this is working great. The application is working on 8080.
But as soon as I change the port of management endpoints (so that health check is served on a different port), the following code
management:
server:
port: 8989
endpoints:
health:
sensitive: false
web:
base-path: /
Ref# https://docs.spring.io/spring-boot/docs/2.1.7.RELEASE/reference/html/production-ready-monitoring.html
then the application is throwing a cast exception when accessing the request object in the interceptor
org.springframework.web.util.NestedServletException: Request
processing failed; nested exception is
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot
cast object 'Request(GET
//localhost:8989/testApp/health)#68117e64' with class
'org.springframework.web.context.request.ServletRequestAttributes' to
class 'org.grails.web.servlet.mvc.GrailsWebRequest'
any suggestion to fix the issue.
(Grails 4.0.12, Groovy 2.5.14 and Java 11)
Upgrade to Grails 5. The above functionality working fine with that.
I have the following configuration:
#SpringBootApplication
#EnableFeignClients
public class Application {
#FeignClient(name = "theclient")
public interface TheClient {
...
theclient:
ribbon:
listOfServers: http://server:8080
And have the following test:
#RunWith(SpringRunner.class)
#RestClientTest(TheClient.class)
#ImportAutoConfiguration(
classes = {
RibbonAutoConfiguration.class,
FeignRibbonClientAutoConfiguration.class,
FeignAutoConfiguration.class
}
)
public class TheClientTest {
...
The error I get is Caused by: com.netflix.client.ClientException: Load balancer does not have available server for client: theclient as if the application.yaml was not read. If I add, however, a config.properties file with the theclient.ribbon.listOfServers=http://server:8080, the tests works and passes.
With #TestPropertySource("classpath:application.yaml") I see in the logs propertySourceLocations = '{classpath:application.yaml}' but I will get the same error.
I also tried to disable ribbon, by adding:
spring:
cloud:
loadbalancer:
ribbon:
enable: false
but it won't work.
I appreciate your input and help.
I recently replaced Hystrix with resilience4j with spring cloud. Most of the unit test are working fine but now I am getting 504 gateway timeout after 1 second. Is there anyway, I can configure the timeout in the properties? So far, I have added
#Bean
public Customizer<ReactiveResilience4JCircuitBreakerFactory> defaultCustomizer() {
return factory -> factory.configureDefault(id -> new Resilience4JConfigBuilder(id)
.circuitBreakerConfig(CircuitBreakerConfig.custom()
.minimumNumberOfCalls(5).failureRateThreshold(20)
.build())
.timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(10))
.build())
.build());
}
And also set the properties in application.yml file
spring:
cloud:
config:
enabled: false
gateway:
httpclient:
response-timeout: 6s
connect-timeout: 6000
Is there any other timeout, I need to configure?
Is there any workaround to configure the timeoutDuration in TimeLimiterConfig? Right now, timeoutDuration is picking up the default value of 1 second. Thats I am getting a 504.
I try to run Eureka Server and Spring Boot Admin Server in one Application (SBA Docu says this is possible). Eureka is working as intended but the Admin App still shows zero Applications.
Spring Boot Version 2.0.3,
Spring Boot Admin Version 2.0.1
Eureka and SBA Server
#SpringBootApplication
#EnableEurekaServer
#EnableDiscoveryClient
#EnableAdminServer
class KotlintestApplication
fun main(args: Array<String>) {
SpringApplication.run(KotlintestApplication::class.java, *args)
}
Server bootstrap.yml
spring:
application:
name: server
Server application.yml
spring:
boot:
admin:
context-path: /admin
eureka:
instance:
leaseRenewalIntervalInSeconds: 10
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://localhost:8080/eureka
Client
#EnableDiscoveryClient
#SpringBootApplication
class KotlintestApplication
fun main(args: Array<String>) {
SpringApplication.run(KotlintestApplication::class.java, *args)
}
#Configuration
class SecurityPermitAllConfig : WebSecurityConfigurerAdapter() {
#Throws(Exception::class)
override fun configure(http: HttpSecurity) {
http.authorizeRequests().anyRequest().permitAll()
.and().csrf().disable()
}
}
Client bootstrap.yml
spring:
application:
name: client
server:
port: 0
Client application.yml
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: ALWAYS
eureka:
instance:
hostname: localhost
health-check-url-path: /actuator/health
status-page-url-path: /actuator/info
client:
serviceUrl:
defaultZone: http://127.0.0.1:8080/eureka/
Found the answer myself
Remove the fetchRegistry: false from the server application.yaml.
The Server has to fetch the registry to see the clients ...
Btw: You should set an instanceId if you want to run multiple instances with a random port on the same host. Otherwise SBA can't differ between the instances.
eureka:
instance:
instanceId : client-${random.uuid}
I have a simple spring cloud application with side car here is the code:
#SpringBootApplication
#EnableSidecar
public class SidecarApp {
public static void main(String[] args) {
SpringApplication.run(SidecarApp.class, args);
}
}
The side car call to another service via zuul and I am trying to configure the hystrix timeout without success! here is my configurations:
server:
port: 9085
spring:
application:
name: cue
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 100
hystrix.command.default.execution.isolation.thread.interruptOnTimeout: true
hystrix.command.default.execution.timeout.enabled: true
sidecar:
port: 8085
health-uri: http://localhost:8085/health.json
in these configurations I expect that if the call to the other service will take more than 100 miliseconds the hystrix will return immediately, but this is not happened(the service hystrix call take 10 seconds)
Am I misconfiguring something?
Note:
The call to the other service is: http://localhost:9085/cma/myinfo1 so the call arrives to the sidecar and cma is the Eureka name of the remote service and it calls the function myinfo1 in the service cma...
First, I think your yaml file is incorrect,you should use standard format.
You can disable hystrix's timeout check:
hystrix:
command:
default:
execution:
timeout:
enabled: false
Or change Zuul's Hystrix isolation strategy to THREAD:
hystrix:
command:
default:
execution:
isolation:
strategy: THREAD
thread:
timeoutInMilliseconds: 10000