Spring Cloud Consul health check and status configuration on GCP - spring-boot

We are trying to register a spring-cloud-consul application with consul on GCP compute engine, where it is able to register the application with the consul, but there are two problems we are facing with the application. Below is bootstrap.yaml and server.yaml for the application,
application.yaml
server:
port: 10003
spring:
application:
name: hello-service
cloud:
consul:
enabled: true
inetutils:
useOnlySiteLocalInterfaces: true
endpoints:
actuator:
sensitive: false
bootstrap.yaml
spring:
cloud:
consul:
enabled: true
host: 10.160.0.18
port: 8500
discovery:
prefer-ip-address: true
Consul is not able to call health-check on compute engine, possibly because it's registered on the internal domain name of the instance.
service with consul: NewService{id='hello-service-10003',
name='hello-service', tags=[secure=false],
address='consul-app-test.c.name-of-project.internal', meta=null,
port=10003, enableTagOverride=null, check=Check{script='null',
interval='10s', ttl='null',
http='http://consul-app-test.c.name-of-project.internal:10003/actuator/health',
method='null', header={}, tcp='null', timeout='null',
deregisterCriticalServiceAfter='null', tlsSkipVerify=null,
status='null'}, checks=null}
Application, not de-registering from the consul. We have stopped the application still it shows on consul UI.

I made a few changes in the application.yaml and bootstrap.yaml which worked for me.
application.yaml
spring:
application:
name: hello-service
cloud:
consul:
discovery:
instanceId: ${spring.application.name}:${random.value}
health-check-critical-timeout: 3m
prefer-ip-address: true # disable if we want to use google cloud internal DNS
bootstrap.yaml
spring:
cloud:
consul:
enabled: true
host: 10.160.0.18
port: 8500

if you use version 2.1.2 like me: org.springframework.cloud:spring-cloud-starter-consul-discovery:2.1.2.RELEASE
you can set:
spring:
cloud:
consul:
host: localhost # consul的地址
port: 8500 # consul 的端口
discovery:
prefer-ip-address: true # // This must be matched
tags: version=1.0
instance-id: ${spring.application.name}:${spring.cloud.client.ip-address}
healthCheckPath: /actuator/health # 服务做健康检查的端口
healthCheckInterval: 15s # 服务健康检查的周期
healthCheckTimeout: 60s # 服务检查是的timeout时长
healthCheckCriticalTimeout: 5m # 服务健康检查失败5分钟后,删除服务
and you can look the source code in ConsulDiscoveryProperties:
#ConfigurationProperties("spring.cloud.consul.discovery")
public class ConsulDiscoveryProperties {
……
/** Is service discovery enabled? */
private boolean enabled = true;
/** Alternate server path to invoke for health checking. */
private String healthCheckPath = "/actuator/health";
/** Custom health check url to override default. */
private String healthCheckUrl;
/** How often to perform the health check (e.g. 10s), defaults to 10s. */
private String healthCheckInterval = "10s";
/** Timeout for health check (e.g. 10s). */
private String healthCheckTimeout;
/**
* Timeout to deregister services critical for longer than timeout (e.g. 30m).
* Requires consul version 7.x or higher.
*/
private String healthCheckCriticalTimeout;
……

Related

Spring boot config server does not refresh if I update local

I have Spring cloud project which has below information:
Controller of address-service-1:
#RestController
#RequestMapping("/api/address")
#Slf4j
#RefreshScope
public class AddressController {
#Value("${scope-refresh-testing}")
private String message;
#RequestMapping("/scope-refresh-testing-message")
String getMessage() {
return this.message;
}
}
bootstrap.yml of address-service-1:
spring:
application:
name: address-service-1
# register to config server
cloud:
config:
discovery:
enabled: true
service-id: config-server-1
profile: default
management:
endpoints:
web:
exposure:
include:
- refresh
Properties of config-server-1:
server:
port: 8888
spring:
application:
name: config-server-1
cloud:
config:
server:
git:
default-label: master
uri: file:///E:/workspace/Spring-boot-microservices-config-server-study/
Properties which I stored in file:///E:/workspace/Spring-boot-microservices-config-server-study/ (address-service-1.yml):
scope-refresh-testing: testDefault
If I change scope-refresh-testing: testDefault222 then run url actuator/refresh, the properties file will rollback to scope-refresh-testing: testDefault
Did I miss something in configuration?
Thanks

Name or service unknow with eureka server

I use spring boot with eureka.
When I try to start the eureka server, I get
Caused by: java.net.UnknownHostException: MiWiFi-RA72-srv: Name or
service not known
My config
server:
port: 8761
spring:
security:
user:
name: admin
password: password
logging:
level:
org:
springframework:
security: DEBUG
eureka:
client:
registerWithEureka: false
fetchRegistry: false
service-url:
defaultZone: http://admin:password#localhost:8761/eureka/
server:
waitTimeInMsWhenSyncEmpty: 0
instance:
hostname: localhost
prefer-ip-address: true
I tried to replace localhost by MiWiFi-RA72-srv, but I get the same result

virtualHost Not Creating on RabbitMQ server using application.yml springboot and from config server

Virtualhost are not getting created on RabbitMQ server based on configuration
Do i have make sure VH aka Virtual Hosts on RabbitMQ .
Am i missing some configuration.
Please find the configuration below
application.yml
spring:
rabbitmq:
host: 127.0.0.1
virtual-host: /defaultVH
username: defaultUser
password: defaultPassword
cloud:
stream:
bindings:
saviyntSampleQueueA:
binder: rabbit-A
contentType: application/x-java-object
group: groupA
destination: saviyntSampleQueueA
saviyntSampleQueueB:
binder: rabbit-B
contentType: application/x-java-object
group: groupB
destination: saviyntSampleQueueB
binders:
rabbit-A:
defaultCandidate: false
inheritEnvironment: false
type: rabbit
environment:
spring:
rabbitmq:
host: 127.0.0.1
virtualHost: /vhA
username: userA
password: paswdA
port: 5672
connection-timeout: 10000
rabbit-B:
defaultCandidate: false
inheritEnvironment: false
type: rabbit
environment:
spring:
rabbitmq:
host: 127.0.0.1
virtualHost: /vhB
username: userB
password: paswdB
port: 5672
connection-timeout: 10000
bootstrap.yml
############################################
# default settings
############################################
spring:
main:
banner-mode: "off"
application:
name: demo-service
cloud:
config:
enabled: true #change this to use config-service
retry:
maxAttempts: 3
discovery:
enabled: false
fail-fast: true
override-system-properties: false
server:
port: 8080
Added default spring boot added Enable binding
#EnableBinding({MessageChannels.class})
#SpringBootApplication
public class Configissue1124Application {
public static void main(String[] args) {
SpringApplication.run(Configissue1124Application.class, args);
}
}
Now simple straightforward massage channel to to dispatch massage
interface MessageChannels {
#Input("saviyntSampleQueueA")
SubscribableChannel queueA();
#Input("saviyntSampleQueueB")
SubscribableChannel queueB();
}
When i ran the Boot Application its not creating any Virtualhost on the system . i tried using config server buy providing same configuration but still no luck
can you please find if some thing am missing.
Thanks in Advance
The AMQP protocol (or RabbitMQ REST API) provides no mechanism to provision virtual hosts from the client.
Virtual hosts must be provisioned manually on the server.

Eureka service - locations

I am new to spring boot and spring cloud.
I would like to ask if I can have one eureka service for multiple locations (different countries).
For example
One eureka service and one app service which is running twice - for location SLOVAKIA and another one for location CZECH.
And then I want to have edge service for that location and for another common services.
Is it possible?
config eureka-service
spring:
application:
name: eureka-service
server:
port: 8761
eureka:
instance:
preferIpAddress: true
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://localhost:8761/eureka/
config service-common
server:
port: 9082
eureka:
instance:
preferIpAddress: true
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
config service-a
spring:
application:
name: service-a
eureka:
instance:
preferIpAddress: true
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
---
spring:
profiles: sk
server:
port: 9080
eureka:
instance:
metadataMap:
zone: skZone
---
spring:
profiles: cz
server:
port: 9081
eureka:
instance:
metadataMap:
zone: czZone
config service-a-apigateway
spring:
application:
name: service-a-apigateway
zuul:
routes:
book-apigateway:
serviceId: service-a
path: /api/**
book-common-api:
serviceId: service-common
path: /common/**
eureka:
instance:
preferIpAddress: true
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
---
spring:
profiles: sk
server:
port: 9050
eureka:
instance:
metadataMap:
zone: skZone
---
spring:
profiles: cz
server:
port: 9051
eureka:
instance:
metadataMap:
zone: czZone
Service-a-apigateway (profile: sk) can call only service-a (profile: sk) and service-common. Profile (cz) has the same behavior. It is good.
But when service-a (profile: sk) is down, service-a-apigateway (profile: sk) can call service-a (profile: cz). This behavior is undesirable.
I think so, by setting property eureka.instance.metadataMap.zone on both zuul edge and service A.
"By default it will be used to locate a server in the same zone as the client..."
http://cloud.spring.io/spring-cloud-static/spring-cloud.html#_using_ribbon_with_eureka
I was able to resolve it when I had three eureka services running and one of them (common eureka) replicates to the remaining two services. But I don't know if it's a good idea.

How to add into Turbine additional Hystrix metrics aggregations

My setup is spring boot cloud using netflix library
I managed to have Turbine aggregating Hystrix metrics from one service. However when I add more services I cant see them.
This is my setup (also uploaded this into github at:
Project On Github
Service 1:
FlightIntegrationService:
#SpringBootApplication
#EnableCircuitBreaker
#EnableDiscoveryClient
#ComponentScan("com.bootnetflix")
public class FlightIntegrationApplication {
..
}
application.yaml
server:
port: 0
eureka:
instance:
leaseRenewalIntervalInSeconds: 10
metadataMap:
instanceId: ${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${random.value}}}
client:
registryFetchIntervalSeconds: 5
bootstrap.yaml
spring:
application:
name: flight-integration-service
service 2:
Coupon service:
#SpringBootApplication
#EnableCircuitBreaker
#EnableDiscoveryClient
#ComponentScan("com.bootnetflix")
public class CouponServiceApp {
..
}
application yaml:
server:
port: 0
eureka:
instance:
leaseRenewalIntervalInSeconds: 10
metadataMap:
instanceId: ${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${random.value}}}
client:
registryFetchIntervalSeconds: 5
Eureka app service:
#SpringBootApplication
#EnableEurekaServer
public class EurekaApplication {
Hystrix dashboard service:
#SpringBootApplication
#EnableHystrixDashboard
#Controller
public class HystrixDashboardApplication {
application.yaml:
info:
component: Hystrix Dashboard
endpoints:
restart:
enabled: true
shutdown:
enabled: true
server:
port: 7979
logging:
level:
ROOT: INFO
org.springframework.web: DEBUG
eureka:
client:
region: default
preferSameZone: false
us-east-1:
availabilityZones: default
instance:
virtualHostName: ${spring.application.name}
bootstrap.yaml
spring:
application:
name: hystrixdashboard
and finally Turbine-service:
EnableAutoConfiguration
#EnableTurbine
#EnableEurekaClient
#EnableHystrixDashboard
public class TurbineApplication {
application.yaml:
info:
component: Turbine
PREFIX:
endpoints:
restart:
enabled: true
shutdown:
enabled: true
server:
port: 8989
management:
port: 8990
eureka:
instance:
leaseRenewalIntervalInSeconds: 10
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
#turbine:
# aggregator:
# clusterConfig: FLIGHT-INTEGRATION-SERVICE,COUPON-SERVICE
#appConfig: flight-integration-service,coupon-service
#turbine:
# clusterNameExpression: 'default'
# appConfig: flight-integration-service,coupon-service
turbine:
appConfig: coupon-service,flight-integration-service
clusterNameExpression: new String('default')
#As you can see I tried diff configurations.
What am i doing wrong? why I cant actually aggregate both services hystrix metrics(flight-integration service,coupon-service)
Thank you.
solved by #spencergibb suggestation. I added to each of the client the dependency of spring-boot-starter-amqp and created rabbitMQ broker. Turbine is aggregating all messages via amqp and I was able to see all Hystrix commands aggregated on my hystrix dashboard server

Resources