spring cloud unable to route to internal application - spring

I am using spring cloud to route application but unable to do so below are the details
Gateway configuration
port: 8080
debug: true
spring:
application:
name: cloud-gateway
cloud:
gateway:
discovery:
locator:
enabled: true
lower-case-senstive: true
routes:
- id: product-composite
uri: localhost:7000
predicates:
- Path: /product-composite/**
eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
server:
port: 8761
waitTimeInMsWhenSyncEmpty: 0
response-cache-update-interval: 5000
management.endpoints.web.exposure.include: '*'
Product Composite Service* (I am trying to call)
port: 7000
spring:
application:
name: product-composite
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
initialInstanceInfoReplicationIntervalSeconds: 5
registryFetchIntervalSeconds: 5
register-with-eureka: true
fetch-registery: true
instance:
leaseRenewalIntervalInSeconds: 5
leaseExpirationDurationInSeconds: 5
Path
#RestController
public class ProductCompositeServiceController {
#GetMapping
public String getString() {
return "Hello grom product CompositeController";
}
}
Can you help? If needed I can provide more details
Note: if product-composite-servcie is called without eureka I am getting response but with eureka I am getting
404 Resource not found
Edit
Below is the stacktrace I am getting so far:
2020-06-24 22:22:05.252 DEBUG 38876 --- [or-http-epoll-2] o.s.w.r.handler.SimpleUrlHandlerMapping : [63939523-1] Mapped to ResourceWebHandler ["classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/"]
2020-06-24 22:22:05.255 DEBUG 38876 --- [or-http-epoll-2] o.s.w.r.resource.ResourceWebHandler : [63939523-1] Resource not found
2020-06-24 22:22:05.273 DEBUG 38876 --- [or-http-epoll-2] a.w.r.e.AbstractErrorWebExceptionHandler : [63939523-1] Resolved [ResponseStatusException: 404 NOT_FOUND] for HTTP GET /product-composite/
2020-06-24 22:22:05.281 DEBUG 38876 --- [or-http-epoll-2] o.s.http.codec.json.Jackson2JsonEncoder : [63939523-1] Encoding [{timestamp=Wed Jun 24 22:22:05 IST 2020, path=/product-composite/, status=404, error=Not Found, mess (truncated)...]
2020-06-24 22:22:05.299 DEBUG 38876 --- [or-http-epoll-2] o.s.w.s.adapter.HttpWebHandlerAdapter : [63939523-1] Completed 404 NOT_FOUND
I also tried to add path as
routes:
- id: product-composite
uri: localhost:7000
predicates:
- Path: /product-composite/**
filters:
- RewritePath: /product-composite/(?<segment>.*), /$\{segment}

You don't have a path in your controller. Try
#GetMapping("/product-composite")

Related

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

Eureka preferIpAddress: true is not working with spring boot 2.1.3 'Greenwich.RELEASE' '

Due to some reasons, I want microservices clients to be registered into Eureka with their IP address, instead of host name.
This is not working even after setting eureka: instance: preferIpAddress: true [yaml given below].
Still eureka display only host names. Anyone faced this type of issue and possible remedy would be really helpful.
Springbootversion : 2.1.3 , Spring cloud - Greenwich Release
application.yml of microservice instance Please note the preferIpAddress: true
spring:
profiles: default
application:
name: booking
cloud:
config:
uri: http://localhost:8888,http://localhost:8889
eureka:
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://localhost:8761/eureka
healthcheck:
enabled: false
instance:
leaseRenewalIntervalInSeconds: 1
leaseExpirationDurationInSeconds: 2
preferIpAddress: true
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: ALWAYS
security:
enabled: false
application.yml of Eureka server
spring:
profiles: localpeer1
eureka:
server:
client:
register-with-eureka: false
fetch-registry: false
serviceUrl:
defaultZone: http://localhost:8762/eureka
server:
port: 8761
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: ALWAYS
---
spring:
profiles: localpeer2
eureka:
server:
client:
register-with-eureka: false
fetch-registry: false
serviceUrl:
defaultZone: http://localhost:8761/eureka
server:
port: 8762
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: ALWAYS
Dashboard of Eureka still shows the hostname instead of IP address.
Thanks for the inputs.

How to use eureka.client.service-url: property of netflix eureka in spring cloud

I am trying to add Eureka client in one of the microservices, but i am unable to figure out if how can I use the service-url.
I am using the Greenwich.SR1 version of spring-cloud.
Below is my application.yml
spring:
application:
name: stock-service
server:
port: 9901
eureka:
instance:
hostname: localhost
client:
register-with-eureka: true
fetch-registry: true
service-url: http://${eureka.instance.hostname}:9902/eureka/
I tried to search it out but everywhere I am getting the old way which is not supported in this version:
Old Way:
eureka: #tells about the Eureka server details and its refresh time
instance:
leaseRenewalIntervalInSeconds: 1
leaseExpirationDurationInSeconds: 2
client:
serviceUrl:
defaultZone: http://127.0.0.1:8761/eureka/
Could someone help here?
Finally, I find the configuration:
spring:
application:
name: stock-service
server:
port: 9901
eureka:
instance:
hostname: localhost
client:
register-with-eureka: true
fetch-registry: true
service-url:
default-zone: http://localhost:9902/eureka
I just tried this configuration in Spring Cloud Hoxton.SR4, and it doesn't work.
Then I find out the correct way (at least for me):
spring:
application:
name: hello-world-server
server:
port: 8010
eureka:
client:
service-url:
defaultZone: http://localhost:9001/eureka/
We could see the logs below after starting your client application:
2020-05-02 16:39:21.914 INFO 27104 --- [ main] c.n.d.DiscoveryClient : Discovery Client initialized at timestamp 1588408761914 with initial instances count: 0
2020-05-02 16:39:21.915 INFO 27104 --- [ main] o.s.c.n.e.s.EurekaServiceRegistry : Registering application HELLO-WORLD-SERVER with eureka with status UP
2020-05-02 16:39:21.915 INFO 27104 --- [ main] c.n.d.DiscoveryClient : Saw local status change event StatusChangeEvent [timestamp=1588408761915, current=UP, previous=STARTING]
2020-05-02 16:39:21.916 INFO 27104 --- [nfoReplicator-0] c.n.d.DiscoveryClient : DiscoveryClient_HELLO-WORLD-SERVER/tumbleweed:hello-world-server:8010: registering service...
And the Server side:
It works!

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