I'm trying to setup Spring cloud gateway on openshift and want to discover the services available within cluster. I'm able to discover the services by adding the #DiscoveryClient and dependencies as below.
Boot dependencies are like:
spring-cloud.version : Greenwich.SR2
spring-boot-starter-parent:2.1.7.RELEASE
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-kubernetes</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-kubernetes-ribbon</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
</dependency>
I can see services are being discovered and registered. And routing also happening but there is CN name validation error occurring while routing. I tried setting the use-insecure-trust-manager:true as well but still the same error.
2021-12-31 12:30:33.867 TRACE 1 --- [or-http-epoll-8] o.s.c.g.h.p.RoutePredicateFactory : Pattern "[/customer-service/**]" does not match against value "/userprofile/addUser"
2021-12-31 12:30:33.868 TRACE 1 --- [or-http-epoll-8] o.s.c.g.h.p.RoutePredicateFactory : Pattern "/userprofile/**" matches against value "/userprofile/addUser"
2021-12-31 12:30:33.868 DEBUG 1 --- [or-http-epoll-8] o.s.c.g.h.RoutePredicateHandlerMapping : Route matched: CompositeDiscoveryClient_userprofile
2021-12-31 12:30:33.868 DEBUG 1 --- [or-http-epoll-8] o.s.c.g.h.RoutePredicateHandlerMapping : Mapping [Exchange: GET https://my-gatewat.net/userprofile/addUser ] to Route{id='CompositeDiscoveryClient_userprofile', uri=lb://userprofile, order=0, predicate=org.springframework.cloud.gateway.support.ServerWebExchangeUtils$$Lambda$712/0x000000010072a440#1046479, gatewayFilters=[OrderedGatewayFilter{delegate=org.springframework.cloud.gateway.filter.factory.RewritePathGatewayFilterFactory$$Lambda$713/0x000000010072a840#3c8d9cd1, order=1}]}
2021-12-31 12:30:33.888 TRACE 1 --- [or-http-epoll-8] o.s.c.g.filter.RouteToRequestUrlFilter : RouteToRequestUrlFilter start
2021-12-31 12:30:33.888 TRACE 1 --- [or-http-epoll-8] o.s.c.g.filter.LoadBalancerClientFilter : LoadBalancerClientFilter url before: lb://userprofile/addUser
2021-12-31 12:30:33.889 TRACE 1 --- [or-http-epoll-8] o.s.c.g.filter.LoadBalancerClientFilter : LoadBalancerClientFilter url chosen: https://10.130.83.26:8443/addUser
2021-12-31 12:30:33.891 DEBUG 1 --- [ctor-http-nio-7] r.n.resources.PooledConnectionProvider : [id: 0x326a2e7b] Created new pooled channel, now 0 active connections and 1 inactive connections
2021-12-31 12:30:33.891 DEBUG 1 --- [ctor-http-nio-7] reactor.netty.tcp.SslProvider : [id: 0x326a2e7b] SSL enabled using engine SSLEngineImpl and SNI /10.130.83.26:8443
2021-12-31 12:30:33.931 ERROR 1 --- [ctor-http-nio-7] a.w.r.e.AbstractErrorWebExceptionHandler : [8768bf6c] 500 Server Error for HTTP GET "/userprofile/addUser"
javax.net.ssl.SSLHandshakeException: No subject alternative names matching IP address 10.130.83.26 found
at java.base/sun.security.ssl.Alert.createSSLException(Unknown Source) ~[na:na]
at java.base/sun.security.ssl.TransportContext.fatal(Unknown Source) ~[na:na]
Application.yml:
spring:
application:
name: my-api-gateway
cloud:
gateway:
discovery:
locator:
enabled: true
httpclient:
ssl:
use-insecure-trust-manager: true
Tried adding SNI matchers in SSL Context, to skip hostname check, but still not working:
SNIMatcher matcher = new SNIMatcher(0) {
#Override
public boolean matches(SNIServerName serverName) {
log.info("Server Name validation:{}", serverName);
return true;
}
};
I'm able to resolve this error by using k8s discovery with url-expression as below:
spring:
cloud:
gateway:
discovery:
locator:
enabled: true
lower-case-service-id: true
url-expression: "'https://'+serviceId+':'+getPort()"
Routes will be registered as https://serivcename:port same URL will be used by SSLProvider where it will create SSLHandler with host in SNI Information rather IP-Address which was causing this failure.
Logs for where SSL provider added handler with SSL Engine only and hostname port.
2022-01-04 14:58:15.360 DEBUG 1 --- [or-http-epoll-4] reactor.netty.tcp.SslProvider : [63cc8609, L:/127.0.0.1:8091 - R:/127.0.0.1:60004] SSL enabled using engine io.netty.handler.ssl.JdkAlpnSslEngine#31e2342b and SNI my-service:8088
Related
I'm developing an API on Spring Boot using Vault and Mongo, but it refuses to start.
2022-09-07 13:58:56.510 WARN 23885 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.cloud.vault.config.VaultReactiveBootstrapConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'spring.cloud.vault-org.springframework.cloud.vault.config.VaultProperties': Could not bind properties to 'VaultProperties' : prefix=spring.cloud.vault, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is javax.validation.NoProviderFoundException: Unable to create a Configuration, because no Jakarta Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath.
2022-09-07 13:58:56.513 INFO 23885 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-09-07 13:58:56.521 ERROR 23885 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
The Bean Validation API is on the classpath but no implementation could be found
Action:
Add an implementation, such as Hibernate Validator, to the classpath
EDIT: I think the problem is that Spring Boot tries to use javax and jakarta at the same time according to this part of the error:
nested exception is javax.validation.NoProviderFoundException: Unable to create a Configuration, because no Jakarta Bean Validation provider could be found.. Is this a normal behavior?
Consider to bypass the problem: try to add compile 'de.flapdoodle.embed:de.flapdoodle.embed.mongo' to your build.gradle, and #Bean public MongoClient embeddedMongoClient() to return a dummy Mongo client during the Init phase.
The real mongo Url could be fetched (and used) from the Vault later, during run time, once required, via a customized extends of spring-data-mongodb's MongoDbFactory.
Adding hibernate-validator 6 and spring-boot-starter-validation solved the problem.
Thing to know: hibernate-validator < 7 uses Javax, hibernate-validator => 7 uses Jakarta.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.2.4.Final</version>
</dependency>
I have Spring Cloud config server and trying to register it to Spring Boot admin. In my pom.xml file I have
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-client</artifactId>
<version>2.1.6</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
<version>2.1.3.Release</version>
</dependency>
I have several other services registering, so I know I have all my URL and settings correct. But I am not seeing is the registering log in the config server logs.
Found the answer after running the config server in debug mode.
SpringBootAdminClientAutoConfiguration:
Did not match:
- Spring Boot Client is disabled, because 'spring.boot.admin.client.url' is empty. (SpringBootAdminClientEnabledCondition)
Matched:
- #ConditionalOnWebApplication (required) found 'session' scope (OnWebApplicationCondition)
SpringBootAdminClientCloudFoundryAutoConfiguration:
Did not match:
- Spring Boot Client is disabled, because 'spring.boot.admin.client.url' is empty. (SpringBootAdminClientEnabledCondition)
Matched:
- #ConditionalOnWebApplication (required) found 'session' scope (OnWebApplicationCondition)
Since the config server doesn't read from the config server git repo the client URL was not set.
Adding --spring.boot.admin.client.url=<url> to the startup fixed it.
I am facing issues using Zuul and Ribbon. I am using also Eureka for microservice registry.
I have ribbon-service(port 9000) communicating with the user-service using the REST API
user-service has 2 instances (on port 8081 and 8091)
on ribbon-service I have implemented client-side load balancing using hystrix and feign client
I consume ribbon-service API using Zuul route, and this API then triggers user-service API
When I start my microservice ecosystem and try to consume ribbon-service API(zuulservice:8761/ribbon-service/) I get the following error:
com.netflix.zuul.exception.ZuulException: Forwarding error
at org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.handleException(RibbonRoutingFilter.java:189) ~[spring-cloud-netflix-zuul-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.forward(RibbonRoutingFilter.java:164) ~[spring-cloud-netflix-zuul-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.run(RibbonRoutingFilter.java:112) ~[spring-cloud-netflix-zuul-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at com.netflix.zuul.ZuulFilter.runFilter(ZuulFilter.java:117) ~[zuul-core-1.3.1.jar:1.3.1]
at com.netflix.zuul.FilterProcessor.processZuulFilter(FilterProcessor.java:193) ~[zuul-core-1.3.1.jar:1.3.1]
at com.netflix.zuul.FilterProcessor.runFilters(FilterProcessor.java:157) ~[zuul-core-1.3.1.jar:1.3.1]
at com.netflix.zuul.FilterProcessor.route(FilterProcessor.java:118) ~[zuul-core-1.3.1.jar:1.3.1]
at com.netflix.zuul.ZuulRunner.route(ZuulRunner.java:96) ~[zuul-core-1.3.1.jar:1.3.1]
at com.netflix.zuul.http.ZuulServlet.route(ZuulServlet.java:116) ~[zuul-core-1.3.1.jar:1.3.1]
at com.netflix.zuul.http.ZuulServlet.service(ZuulServlet.java:81) ~[zuul-core-1.3.1.jar:1.3.1]
at org.springframework.web.servlet.mvc.ServletWrappingController.handleRequestInternal(ServletWrappingController.java:165) [spring-webmvc-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.cloud.netflix.zuul.web.ZuulController.handleRequest(ZuulController.java:44) [spring-cloud-netflix-zuul-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:52) [spring-webmvc-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991) [spring-webmvc-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925) [spring-webmvc-5.0.5.RELEASE.jar:5.0.5.RELEASE]................
Caused by: com.netflix.client.ClientException: Load balancer does not have available server for client: ribbon-service
at com.netflix.loadbalancer.LoadBalancerContext.getServerFromLoadBalancer(LoadBalancerContext.java:483) ~[ribbon-loadbalancer-2.2.5.jar:2.2.5]
at com.netflix.loadbalancer.reactive.LoadBalancerCommand$1.call(LoadBalancerCommand.java:184) ~[ribbon-loadbalancer-2.2.5.jar:2.2.5]
at com.netflix.loadbalancer.reactive.LoadBalancerCommand$1.call(LoadBalancerCommand.java:180) ~[ribbon-loadbalancer-2.2.5.jar:2.2.5]
at rx.Observable.unsafeSubscribe(Observable.java:10327) ~[rxjava-1.3.8.jar:1.3.8]
at rx.internal.operators.OnSubscribeConcatMap.call(OnSubscribeConcatMap.java:94) ~[rxjava-1.3.8.jar:1.3.8]
at rx.internal.operators.OnSubscribeConcatMap.call(OnSubscribeConcatMap.java:42) ~[rxjava-1.3.8.jar:1.3.8]
at rx.Observable.unsafeSubscribe(Observable.java:10327) ~[rxjava-1.3.8.jar:1.3.8]
This error remains for some time, and after that time I get the following output:
2018-07-16 12:55:43.260 INFO 19233 --- [erListUpdater-0] c.netflix.config.ChainedDynamicProperty : Flipping property: ribbon-service.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
After that output everthing works great again.
When I hit eurekaservice:8765/eureka/apps I have registered both ribbon-service and all the user-service instances.
This is my zuul service application.properties:
> #Service port
server.port=8765
#Service port
spring.application.name=zuul-service
# Discovery Server Access
eureka.client.service-url.defaultZone:http://localhost:8761/eureka/
eureka.instance.lease-renewal-interval-in-seconds=3
#User service configuration
zuul.routes.user-service.path:/user-service/**
zuul.routes.user-service.serviceId:user-service
#Product service configuration
zuul.routes.product-service.path:/product-service/**
zuul.routes.product-service.serviceId:product-service
#Product service configuration
zuul.routes.shoppingcart-service.path:/shoppingcart-service/**
zuul.routes.shoppingcart-service.serviceId:shoppingcart-service
#Product service configuration
zuul.routes.payment-service.path:/payment-service/**
zuul.routes.payment-service.serviceId:payment-service
#Product service configuration
zuul.routes.ribbon-service.path:/ribbon-service/**
zuul.routes.ribbon-service.serviceId:ribbon-service
This is my zuul-service bootstrap.properties:
> #Application name
spring.application.name=zuul-service
#hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 12600
ribbon.ConnectTimeout: 6000
ribbon.ReadTimeout: 60000
robbon.eureka.enabled: true
hystrix.command.default.execution.timeout.enabled=false
I am using spring 2.0.1 and spring cloud Finchley.RELEASE.
Can somebody explain what is going on?
Thank you!
The way DiscoveryClient works is that it fetches new list of changes from Eureka (Service discovery) for every defined time period called hearbeat. Until new changes with respect to registered applications propagates from service discovery to your Zuul instance it is bound to have errors.
The output you see in the logs is just the confirmation that it has received this information.
You may consider add strip path config for your zuul configuration.
add stripPrefix=false in every route config
I am trying to develop a spring cloud microservice using spring MVC and spring boot framework. And Eureka server , Zuul , Ribbon , hystrix and Turbine using for spring cloud. I already developed a microservice and implemented only hystrix dashboard. I am able to take hystrix dashboard. Now I am implementing more services. So I choosed turbine for aggregation of monitoring. But it not getting the dashboard.I implemented turbine in separate spring boot project.
My pom.xml containing,
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-turbine</artifactId>
</dependency>
And My main class containing,
#SpringBootApplication
#EnableHystrixDashboard
#EnableCircuitBreaker
#EnableTurbine
public class ZTurbineClientApplication {
public static void main(String[] args) {
SpringApplication.run(ZTurbineClientApplication.class, args);
}
}
And my Turbine project application.properties file containing,
server.port=8085
spring.application.name=espace-Turbine
eureka.client.serviceUrl.defaultZone=http://localhost:8071/eureka/
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
turbine:
aggregator:
clusterConfig: APPCLUSTER
app-config: espaceService1,espaceService2
instanceUrlSuffix.APPCLUSTER: /hystrix.stream
And My previous first services's application.properties file like
eureka.client.serviceUrl.defaultZone=http://localhost:8071/eureka/
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
spring.application.name=espaceService1
server.port=8080
eureka:
instance:
prefer-ip-address: true
leaseRenewalIntervalInSeconds: 3
leaseExpirationDurationInSeconds: 3
metadata-map:
cluster: APPCLUSTER
And second service's application property file contains,
eureka.client.serviceUrl.defaultZone=http://localhost:8071/eureka/
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
spring.application.name=espaceService2
server.port=8081
eureka:
instance:
prefer-ip-address: true
leaseRenewalIntervalInSeconds: 3
leaseExpirationDurationInSeconds: 3
metadata-map:
cluster: APPCLUSTER
these are my implementation details.
After I took URL "http://localhost:8085/hystrix.dashboard". And pasted "http://localhost:8085/turbine.stream?cluster=APPCLUSTER". But getting error like "Unable to connect to Command Metric Stream". Adding screenshots below.
You need to remove space from comma separated service names
turbine.aggregator.cluster-config=espace-Second_Microservice,espaceFirst_Microservice
You cannot aggregate streams from different cluster names, either use one cluster name in both espace-Second_Microservice and espace-First_Microservice or don't use cluster at all.
To define one cluster name use below config
eureka:
instance:
prefer-ip-address: true
leaseRenewalIntervalInSeconds: 3
leaseExpirationDurationInSeconds: 3
metadata-map:
cluster: APPCLUSTER
Use below mentioned config for turbine
turbine:
aggregator:
clusterConfig: APPCLUSTER
app-config: espace-Second_Microservice,espace-First_Microservice
instanceUrlSuffix.APPCLUSTER: /hystrix.stream
Use http://{turbine host}:{turbine Port}/turbine.stream?cluster=APPCLUSTER in Hystrix Dashboard
I am using a consul first setup. For this ,I am using a consul docker image with port 8500 mapped to 8500 so I can successfully use it on local set up.I can access consul at http://localhost:8500 .
I have the following configuration for the config server -
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.RC1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Application.yml
server:
port: 8888
spring:
cloud:
config:
server:
git:
uri: https://github.com/xxxxxx/spring-config-repo.git
consul:
host: consul
port: 8500
enabled: true
discovery:
enabled: true
register: true
service-name: configservice
bootstrap.yml
spring:
application:
name: config-server
ConfigServerApplication.java
#EnableConfigServer
#EnableDiscoveryClient
#SpringBootApplication
public class ConfigServiceApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServiceApplication.class, args);
}
}
When I run this jar, it is successful. I can see the config server in consul ui.
Following are the details of the config server as seen from consul-
Request - http://localhost:8500/v1/catalog/services
Response -
{
"configservice": [],
"consul": []
}
Request - http://localhost:8500/v1/catalog/service/configservice
Response -
[
{
"ID": "f6ac953c-07b9-4097-974e-3ea9cd39bec2",
"Node": "a0954c644062",
"Address": "127.0.0.1",
"TaggedAddresses": {
"lan": "127.0.0.1",
"wan": "127.0.0.1"
},
"NodeMeta": {},
"ServiceID": "config-server-8888",
"ServiceName": "configservice",
"ServiceTags": [],
"ServiceAddress": "10.0.0.158",
"ServicePort": 8888,
"ServiceEnableTagOverride": false,
"CreateIndex": 15,
"ModifyIndex": 15
}
]
I can also access the config server using this uri-
http://localhost:8888/configclient/default
I have client application which uses properties from the config server.My understanding is that when I run this jar, it will contact consul and get the config server information from there and populate the properties by fetching it from the given git uri.
Following are the details about the client -
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-all</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.RC1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
bootstrap.yml
spring:
application:
name: myservice
cloud:
config:
fail-fast: true
retry:
max-attempts: 20
initial-interval: 3000
enabled: true
discovery:
enabled: true
service-id: configserver
consul:
host: localhost
port: 8500
discovery:
enabled: true
register: true
service-name: myservice
application.yml
server:
port: 8081
MyServiceApplication.java
#EnableDiscoveryClient
#SpringBootApplication
public class MyServiceApplication {
public static void main(String[] args) {
SpringApplication.run(ApplePaymentServiceApplication.class, args);
}
}
But during this startup of this jar, its not able to find the config server and instead falls back on the default uri .
This is the relevant startup log section
2017-03-28 00:40:20.407 WARN 99123 --- [ main] lientConfigServiceBootstrapConfiguration : No instances found of configserver (configserver)
2017-03-28 00:40:20.551 INFO 99123 --- [ main] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource [name='consul', propertySources= . [ConsulPropertySource [name='config/myservice/'], ConsulPropertySource [name='config/application/']]]
2017-03-28 00:40:20.587 INFO 99123 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at: http://localhost:8888
2017-03-28 00:40:21.831 INFO 99123 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=myservice, profiles=[default], label=null, version=null, state=null
2017-03-28 00:40:21.832 INFO 99123 --- [ main] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource [name='configService', propertySources=[MapPropertySource [name='https://github.com/xxxxx/spring-config-repo.git/myservice.yml'], MapPropertySource [name='https://github.com/xxxxx/spring-config-repo.git/application.yml']]]
2017-03-28 00:40:21.841 INFO 99123 --- [ main] c.h.MyServiceApplication : No active profile set, falling back to default profiles: default
I tinkered with a lot of different options from various examples such as
consul first bootstrap with spring cloud config
Can someone point to what I might be missing ?
Any pointers to a working example with access to proper application/bootstrap files for consul, configserver and client would be most helpful .
PS: I apologize for the information overload in the question. Some of it might not be relevant but I wanted to give as much information as possible so that someone can spot something that they have encountered before.
You're trying to look up configserver, but it is registered as configservice.