Services not registered with Eureka - spring-boot

I used spring-cloud-starter-eureka 1.4.5 and spring-boot 2.0.4 versions.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
<version>1.4.5.RELEASE</version>
</dependency>
Below mention the eureka configurations in the project.
spring:
application:
name: project-name
eureka:
client:
serviceUrl:
defaultZone: http://secodaryip:port/eureka/,http://primaryip:port/eureka/
cloud:
config:
uri: ${vcap.services.${PREFIX:}configserver.credentials.uri:http://user:password#localhost:8000}
The issue is, there are eight instances need to register in Eureka. For primary IP there is eight instances are registered but in secondary IP there are only five instances are registered. For secondary IP, also should have eight instances are registered.
Difficult to find any solution. Any help or workaround can be really appreciated.

Your clients will connect to the first host from your eureka.client.serviceUrl.defaultZone config. Only if it's not available the second host will be used.
Could you also post your eureka-server config? Do you have peer-awareness between eureka nodes? If you want to replicate services state between eureka nodes you should have something like that in your eureka config:
node1:
eureka:
client:
serviceUrl:
defaultZone: http://secodaryip:port/eureka/
node2:
eureka:
client:
serviceUrl:
defaultZone: http://primaryip:port/eureka/

Related

How to Temporarily Disable Eureka Server support in Ribbon and FeignClient

I have two micro-services(car-management-service & rent-management-service), in rent-management-service i'm calling car-management-service through Ribbon& FeignClient with the help of Eureka Discovery Server. And it's working perfectly.
I have started three instances of car-management-service running on port (8100,8101,8102), and Eureka provide these three instances perfectly one after the other.
Now I want to try is it possible to limit this to call only two of these instances by disabling (Temporary- just to Test is it possible) Eureka and providing direct urls of the car-management-service instances while still keeping Ribbon & FeignClient.
Portion of the application.yml of rent-management-service
eureka:
client:
service-url:
defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}
car-management-service:
ribbon:
eureka:
enabled: false
listOfServers: localhost:8100, localhost:8101
#listOfServers: localhost:8100, localhost:8101, localhost:8102
ServerListRefreshInterval: 1000
Portion of the application.yml of car-management-service
server:
port: 8100
eureka:
client:
enabled: true
service-url:
defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}
Even though I have disabled Eureka in rent-management-service for discover car-management-service instances and hardcoded two of the three running car-management-service instances, rent-management-service still picks up all the three instances.
Why is it happening? Is there wrong with application.yml configuration or rent-management-service still picks up all the three car-management-service instances because they have the Eureka server dependency in pom.xml?
if I understand right you want 3rd instance from your car-management-service not to get traffic from discovery service. isn't it? you run 3 instances but you want to keep one away from eureka?
you can do this.
run 2 instances from car-management-service and in 3rd instance add bellow property
eureka:
client:
fetch-registry: false
register-with-eureka: false
in this case that 3rd service will not register with eureka.

Why microservice accepts request event though it is down in eureka server registry?

I have few microservices which is registered to Eureka Server(http://localhost:10100)
I am removing instance from eureka server using below REST API
Ref : https://github.com/Netflix/eureka/wiki/Eureka-REST-operations
1) Remove instance from eureka server (DELETE) (It remove instance but again re-register..)
http://localhost:10100/eureka/apps/MICRO-SERVICE-1/localhost:micro-service-1:10501
2) Update status of service to DOWN/OUT_OF_SERVICE
http://localhost:10100/eureka/apps/MICRO-SERVICE-1/localhost:micro-service-1:10501/status?value=DOWN
So even when micro-service-1 status is set to DOWN/OUT_OF_SERVICE I am able to send request to micro-service-1 (http://localhost:10501/MyService/hello)
Instead it should be unavailable but it accepting request an giving response.
So, Why microservice accepts request event though it's status is down in eureka server registry ?
Eureka Server application.yml file
server:
port: 10100
address: localhost
eureka:
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://localhost:10100/eureka/
instance:
prefer-ip-address: true
server:
enable-self-preservation: true
wait-time-in-ms-when-sync-empty: 0
Eureka Client (micro-service-1) application.yml file
server:
port: 10501
address: localhost
eureka:
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://localhost:10100/eureka/
instance:
hostname: localhost
prefer-ip-address: true
Your service has no built-in way of interpreting that you've taken it down in Eureka so calling your service by directly hitting its port will always work.
To make use of the directory's knowledge of server status and multiple instances of servers you need to call your service from an API such as ribbon that can construct a software load balancer from the directory. Alternatively make your calls through the Zuul API proxy which is essentially just a microservice built around ribbon internally.
In all these cases remember that the cloud microservices are eventually consistent. That is, changes you make may not be instantly available and will take time to propagate out to the running services.

Is it possible to register with eureka with Discovery first?

I'm trying to achieve a discovery first spring cloud config mode.
This is my client bootstrap.yml
server:
port: 9090
spring:
application:
name: test-config
cloud:
config:
fail-fast: true
discovery:
enabled: true
serviceId: configservice
eureka:
client:
register-with-eureka: true
serviceUrl.defaultZone: http://localhost:8011/eureka/
The configuration is fetched ok, the client starts but is not registered with eureka
So when I look at the eureka dashboard i see only the config service not the client app. The documentation does not state explicitly that this does not work(if I understand it correctly).
Is this on purpose?
Is this a bug?
Is there a possibility to achieve this setup?
Does your main class include: #EnableEurekaClient?
Could you verify your yml properties are properly spaced?

Netflix Turbine does not display cluster hystrix stream

I tried to use Netflix Turbine (1.1.5) to group hystrix (1.1.5) streams.
Turbine App configuration:
spring.application.name=moritoring_server
server.port=8989
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka
eureka.instance.preferIpAddress=true
turbine.aggregator.clusterConfig=MPI_Services
turbine.appconfig=MPI_Services
Healthy-checks App which used hystrix and need to be displayed in Turbine Dashboard:
spring.application.name=health_checks_service
spring.cloud.config.enabled=true
spring.cloud.config.discovery.enabled=true
spring.cloud.config.discovery.serviceId=MPI_Services
server.port=8081
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka
eureka.instance.preferIpAddress=true
eureka.instance.metadataMap.cluster=MPI_Services
I can see the cluster from Eureka as below and individual Hystrix stream from Turbine is fine,
However, I cannot use cluster in Turbine stream and it seems keep loading,
Could someone please advise me how to fix the issue?
Thanks,
Sean
Several points to check here.
1) The application that you are monitoring is providing hystrix.stream on port 8081. Try setting eureka.instance.metadataMap.management.port to 8081 in the application so that Turbine could be able to figure out the correct port. Check this one for detials.
2) I would try avoiding mixing the upper and lower case letters in the cluster names
3) When checking out the Hystrix Dashboard for shoing Turbine stream, make sure you call the demo app so that some statistics get generated. Dashboard remains empty (loading) until first messages pass through the Hystrix command
4) Wait until the Turbine app actually discovers the application cluster (check for "Found hosts" and "Hosts up" messages in the Turbine application logs). This happens after a certain timeout interval, not immediately after application startup
Here is a config that worked for me with Spring Cloud Dalston.SR1
Demo application.yml:
management:
security:
enabled: false
port: 8081
hystrix:
enabled: true
Demo bootstrap.yml:
spring:
application:
name: demo-service
cloud:
config:
discovery:
enabled: true
serviceId: config-service
eureka:
client:
register-with-eureka: false
serviceUrl:
defaultZone: http://localhost:8761/eureka/
instance:
hostname: ${APPLICATION_DOMAIN:localhost}
nonSecurePort: 8090
metadataMap:
management.port: 8082
Hystrix Dashboard & Turbine bootstrap.yml
spring:
application:
name: hystrix-service
cloud:
config:
discovery:
enabled: true
serviceId: config-service
eureka:
client:
register-with-eureka: false
serviceUrl:
defaultZone: http://localhost:8761/eureka/
Hystrix Dashboard & Turbine application.yml
...
turbine:
aggregator:
clusterConfig: DEMO-SERVICE
appConfig: demo-service
After all pieces of the solution are started, the Hystrix dashboard is available at
http://localhost:8989/hystrix
The Turbine stream URL to use is then
http://localhost:8989/turbine.stream?cluster=DEMO-SERVICE
The complete Hystrix Dashboard and Turbine URL of the dashboard:
http://localhost:8989/hystrix/monitor?stream=http%3A%2F%2Flocalhost%3A8989%2Fturbine.stream%3Fcluster%3DDEMO-SERVICE

Zuul Routing when using eureka services

I have a reasonably simple Spring Cloud Netflix setup. We are using Zuul as a reverse proxy and Eureka for service discovery and registry. we have legacy services we are slowly choking out. We have many simple services that have their endpoints configured like this:
{host}:{port}/{service-name}/**
so now when each service is registered with eureka, and subsequently has a route added to Zuul, the zuul endpoint looks like this:
{zuul-host}:{zuul-port}/{service-name}/{service-name}/**
I want to stop Zuul from striping the prefix off the routed URIs for eureka services so that my zuul endpoints look like this:
{zuul-host}:{zuul-port}/{service-name}/**
and forward to:
{zuul-host}:{zuul-port}/{service-name}/**
I would like this to be done in a way such that I do not have to add configs for each and every service.
I would have assumed that zuul.strip-prefix would have done the trick, but that doesn't appear to be the case.
current Zuul application.yml:
zuul:
routes:
oldservice:
path: /oldservice/**
url: http://oldservice-host:9080/api/v1/oldservice
strip-prefix: false
eureka:
client:
serviceUrl:
defaultZone: http://eureka-host:8761/eureka/
Anyone have a suggestion for how I can configure zuul in this way?
Since you are registering your service with eureka why not use the service-id for routing like below.
the service-id is the id that your service gets registered in Eureka with.
zuul:
routes:
path: /oldservice/**
service-id: oldservice
strip-prefix: false
eureka:
client:
serviceUrl:
defaultZone: http://eureka-host:8761/eureka/
For your current scenario I moved the strip-prefix inside the routes I have it like that in my system you can try that.
zuul:
routes:
oldservice:
path: /oldservice/**
url: http://oldservice-host:9080/api/v1/oldservice
strip-prefix: false
eureka:
client:
serviceUrl:
defaultZone: http://eureka-host:8761/eureka/

Resources