Is it possible to register with eureka with Discovery first? - spring

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?

Related

Spring boot application ,accessing routs with gateway service gives white label error?

Hey Guys I was developing a simple project with spring boot, which has 2 services user and blogs and I am using eureka server and I tried to implement a gateway service and it also got registered on the eureka server also but I cannot access the route paths of either user or blog service can anyone please help me with this. This the application.yml file for the gateway service.
server:
port: 3030
spring:
application:
name: gateway-service
cloud:
gateway:
routes:
- id: userModule
uri: http://localhost:3001/
predicates:
- Path=/users/**
- id: blogModule
uri: http://localhost:3002/
predicates:
- Path=/blogs/**
eureka:
client:
serviceUrl:
defaultZone: http://localhost:3000/eureka
registerWithEureka:
- true
fetchRegistry:
- true

Services not registered with Eureka

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/

Auto-configure routes with Zuul and Eureka

Through reading various books / tutorials, it appears that it is possible to auto-configure routes in Zuul when using it in combination with Eureka service discovery. That means that I don't have to explicitly add routes to Zuul's application.properties.
So I understand this correctly? Or do I still need to add routes explicitly to Zuul in order it to work as a gateway?
I would like it to automatically create routes from the application name's that are registered with Eureka. Is this possible?
(Note: I have actually tried this, but when I go to http://localhost:8762/routes I just get an error page.)
Sure. In most microservices implementations, internal microservices endpoints are not exposed outside. A set of public services will be exposed to the clients using an API gateway.
The zuul proxy internally uses the Eureka Server for service discovery.
I would like it to automatically create routes from the application name's that are registered with Eureka. Is this possible?
Sure. I will show you gateway example.
1. Create your service project (user-service)
create application.properties file
# --- Spring Config
spring:
application:
name: OVND-USER-SERVICE
# Eureka client
eureka:
client:
serviceUrl:
defaultZone: ${EUREKA_URL:http://localhost:8761/eureka/}
2. Setting up Zuul project (Gateway-service)
1.#EnableZuulproxy to tell Spring Boot that this is a Zuul proxy
#SpringBootApplication
#EnableZuulProxy
#EnableDiscoveryClient
public class GatewayServiceApplication {
2.create an application.properties file
# =======================================
# Gateway-service Server Configuration
# =======================================
# --- Spring Config
spring:
application:
name: gateway-service
server:
port: ${PORT:8080}
# Eureka client
eureka:
client:
serviceUrl:
defaultZone: ${EUREKA_URL:http://localhost:8761/eureka/}
zuul:
host:
routes:
## By default, all requests to user service for example will start with: "/user/"
## What will be sent to the user service is what comes after the path defined,
## So, if request is "/user/v1/user/tedkim", user service will get "/v1/user/tedkim".
user-service:
path: /user/**
service-id: OVND-USER-SERVICE
another-service:
path: /another/**
service-id: OVND-ANOTHER-SERVICE
Eureka website ( localhost:8761 )
Yes. You can integrate Zuul with Eureka and configure the routes based on application names registered in Eureka. Just add the following configuration to Zuul application:
zuul:
ignoredServices: "*"
routes:
a-service: /a-service/**
b-service: /b-service/**
c-service: /c-service/**
d-service: /d-service/**

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