SpringCloud Eureka - simple client doesnt register - spring-cloud

I have an Eureka Server where I want to register a very basic SpringBoot service. Unfortunately the service doesnt register although I tried to follow all the articles I could find.
Moreover when I check description of the DiscoveryClient (that gets autowired), I see "Spring Cloud No-op DiscoveryClient" which suggests (as per NoopDiscoveryClient.java source) that Eureka client library isnt found.
In pom I have
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-eureka-client</artifactId>
</dependency>
which if I am right should make sure that proper netflix libraries are in place. #EnableEurekaClient annotation is present. No errors on the console when starting the client, nothing interesting in the Eureka Server console logs.
This is the configuration from the application.yml:
eureka:
client:
serviceUrl:
defaultZone: ${vcap.services.eureka-service.credentials.uri:http://127.0.0.1:8761}/eureka/
Any suggestions are really welcomed as I am running out of ideas :)

http://start.spring.io is your friend. You need to use the starters.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Brixton.M5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
and
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>

Except #spencergibb's answer, in my case it also require <spring-cloud.version> inside the <properties>:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.M3</spring-cloud.version>
</properties>

Related

Spring Cloud Gateway using Keycloak Successful Login, but what's the next step?

I managed to get the keycloak default login:
After successful login, keycloak redirect to uri: {hostname}/oauth2/authorization/keycloak. I'm just not sure where did that come from? Where's the setting in the Keycloak that can change that? I have my redirect uri in keycloak client set to: http://localhost/*. That doesn't do it. Wh
Here're my pom:
<properties>
<java.version>11</java.version>
<spring-cloud.version>Hoxton.SR4</spring-cloud.version>
</properties>
...
<!-- gateway -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!-- end of gateway -->
<!-- using CircuitBreaker -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-circuitbreaker-reactor-resilience4j</artifactId>
</dependency>
<!-- end of CircuitBreaker -->
<!-- oauth2 keycloak -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-security</artifactId>
</dependency>
<!-- end of oauth2 keycloak -->
This is my gateway and keycloak settings in application.properties:
#Gateway
spring.cloud.gateway.routes[0].id=person
spring.cloud.gateway.routes[0].uri=http://localhost:8022/
spring.cloud.gateway.routes[0].predicates[0].name=Path
spring.cloud.gateway.routes[0].predicates[0].args[pattern]=/personprocess/**
spring.cloud.gateway.routes[0].filters[0].name=CircuitBreaker
spring.cloud.gateway.routes[0].filters[0].args[name]=myCircuitBreaker
spring.cloud.gateway.routes[0].filters[0].args[fallbackUri]=forward:/myCircuitBreaker/inCaseOfFailureUseThis
spring.cloud.gateway.routes[1].id=keycloak
spring.cloud.gateway.routes[1].uri=http://localhost:8180/
spring.cloud.gateway.routes[1].predicates[0].name=Path
spring.cloud.gateway.routes[1].predicates[0].args[pattern]=/auth/**
spring.cloud.gateway.routes[1].filters[0].name=TokenRelay
spring.cloud.gateway.routes[1].filters[1].name=RemoveRequestHeader
spring.cloud.gateway.routes[1].filters[1].args[name]=Cookie
#Keycloak
spring.security.oauth2.client.registration.keycloak.client-id=gateway-app
spring.security.oauth2.client.registration.keycloak.client-secret=f52b34e1-3cae-4de7-83ae-2d795e3b72d7
spring.security.oauth2.client.registration.keycloak.clientName=gateway-app
spring.security.oauth2.client.registration.keycloak.authorization-grant-type=authorization_code
spring.security.oauth2.client.registration.keycloak.redirectUri=http://localhost/personprocess/
spring.security.oauth2.client.provider.keycloak.authorization-uri=http://localhost:8180/auth/realms/gateway-realm/protocol/openid-connect/auth
spring.security.oauth2.client.provider.keycloak.token-uri=http://localhost:8180/auth/realms/gateway-realm/protocol/openid-connect/token
spring.security.oauth2.client.provider.keycloak.user-info-uri=http://localhost:8180/auth/realms/gateway-realm/protocol/openid-connect/userinfo
spring.security.oauth2.client.provider.keycloak.jwk-set-uri=http://localhost:8180/auth/realms/gateway-realm/protocol/openid-connect/certs
spring.security.oauth2.client.provider.keycloak.user-name-attribute=
I have tested the security token using Postman, and it is all valid. What's the next step?
I found out that you can't mix gateway and spring security in a single pom.
The solution is to split the the apps into a gateway and a spring security.

pause enpoint is not available

I am using Finchley.SR1 with following cloud dependency
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons</artifactId>
</dependency>
I have enabled pause config like this
endpoints:
restart:
enabled: true
pause:
enabled: true
Still no pause and resume endpoint available is actuator like before
{"_links":{"self":{"href":"http://localhost:18182/actuator","templated":false},"archaius":{"href":"http://localhost:18182/actuator/archaius","templated":false},"auditevents":{"href":"http://localhost:18182/actuator/auditevents","templated":false},"beans":{"href":"http://localhost:18182/actuator/beans","templated":false},"health":{"href":"http://localhost:18182/actuator/health","templated":false},"conditions":{"href":"http://localhost:18182/actuator/conditions","templated":false},"configprops":{"href":"http://localhost:18182/actuator/configprops","templated":false},"env-toMatch":{"href":"http://localhost:18182/actuator/env/{toMatch}","templated":true},"env":{"href":"http://localhost:18182/actuator/env","templated":false},"info":{"href":"http://localhost:18182/actuator/info","templated":false},"loggers":{"href":"http://localhost:18182/actuator/loggers","templated":false},"loggers-name":{"href":"http://localhost:18182/actuator/loggers/{name}","templated":true},"heapdump":{"href":"http://localhost:18182/actuator/heapdump","templated":false},"threaddump":{"href":"http://localhost:18182/actuator/threaddump","templated":false},"metrics":{"href":"http://localhost:18182/actuator/metrics","templated":false},"metrics-requiredMetricName":{"href":"http://localhost:18182/actuator/metrics/{requiredMetricName}","templated":true},"scheduledtasks":{"href":"http://localhost:18182/actuator/scheduledtasks","templated":false},"httptrace":{"href":"http://localhost:18182/actuator/httptrace","templated":false},"mappings":{"href":"http://localhost:18182/actuator/mappings","templated":false},"refresh":{"href":"http://localhost:18182/actuator/refresh","templated":false},"features":{"href":"http://localhost:18182/actuator/features","templated":false},"service-registry":{"href":"http://localhost:18182/actuator/service-registry","templated":false},"bindings-name":{"href":"http://localhost:18182/actuator/bindings/{name}","templated":true},"bindings":{"href":"http://localhost:18182/actuator/bindings","templated":false},"channels":{"href":"http://localhost:18182/actuator/channels","templated":false}}
The endpoint configuration properties have been changed since Spring Boot 2.0.
To enable /actuator/restart, /actuator/pause and /actuator/resume you need to use management.endpoint.restart.enabled=true.
Also don't forget to include these endpoints in management.endpoints.web.exposure.include.

Project build error: 'dependencies.dependency.version' for org.springframework.cloud:spring-cloud-starter-config:jar is missing

I'm developing code from the link: https://howtodoinjava.com/spring-cloud/spring-cloud-config-server-git/ and when I updated the Spring Boot version 2.1.2.RELEASE pom.xml is giving me below error.
Project build error: 'dependencies.dependency.version' for org.springframework.cloud:spring-cloud-starter-config:jar is missing.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
The best way is to add a property to define the version of all your spring-cloud dependencies like this:
<properties>
...
<spring-cloud.version>Hoxton.RELEASE</spring-cloud.version>
</properties>
and next add this dependency managment:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

Spring Sleuth stuck sending 10 percent of request to Zipkin

By default Spring Sleuth only sends 10% of requests to Zipkin. By setting spring.sleuth.sampler.percentage you can increase the percentage. Unfortunately it is stuck at 10% regardless of what value I set it to. I have tried 1.0, 0.5, 1, 100.
Output from /env
"spring.sleuth.sampler.percentage": {
"value": 1,
"origin": "class path resource [application.yml]:77:19"
}
Regardless of the value, when I make multiple requests, only 10% make it to Zipkin.
We are using version Finchley.M8 of Spring Cloud and 2.0.0.RELEASE of Spring Boot.
Below are relevant POM settings.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.M8</spring-cloud.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
Could this be a bug?
Ok we found the problem and also a work around.
It looks like all the documentation out there is wrong, at least for the version of Spring Cloud Sleuth we are using. The correct property is not spring.sleuth.sampler.percentage. The correct property is spring.sleuth.sampler.probability
And here is a workaround we found right before noticing that the property was wrong.
#Bean
public Sampler alwaysSampler() {
return Sampler.ALWAYS_SAMPLE;
}
Here are some official documentation from Spring Cloud that contain the wrong property.
https://cloud.spring.io/spring-cloud-static/spring-cloud-sleuth/2.0.0.M5/single/spring-cloud-sleuth.html
https://cloud.spring.io/spring-cloud-sleuth/single/spring-cloud-sleuth.html
Here is the source code that is being used and it is using probability not percentage.
https://github.com/spring-cloud/spring-cloud-sleuth/blob/master/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/sampler/SamplerProperties.java

Spring cloud gateway hystrix not working

I am having issues getting hystrix to work with my route. things like re-write paths and load balancing are working but for some reason hystrix never trips. I am setting my timeouts very low and have a delay in a downstream service. Is there anything special you need to do to get hystrix working?
I am using spring-cloud-gateway with eureka and spring-cloud-config. Also, is there a way to debug when a route is not working? Like a log setting to see what is happening?
Here is my route:
spring:
cloud:
gateway:
routes:
# =====================================
- id: main-service
uri: lbl://main-service
predicates:
- Path=/main-service**
filters:
- Hystrix=mainservice
Here is my pom
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.M7</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-
8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.M5</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
<version>1.4.0.RELEASE</version>
</dependency>
<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>
<version>2.0.0.M2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Here is my Application class:
#EnableDiscoveryClient
#EnableHystrix
#SpringBootApplication
public class GatewayApplication {
public static void main(String[] args) {
SpringApplication.run(GatewayApplication.class, args);
}
}
The only other class in the jar is this:
#Configuration
public class GatewayConfiguration {
#Bean
public DiscoveryClientRouteDefinitionLocator
discoveryClientRouteLocator(DiscoveryClient discoveryClient) {
return new DiscoveryClientRouteDefinitionLocator(discoveryClient);
}
}
I figured out the issue. It seems that if you add eureka discovery then it automatically add routes that match all the spring.application.names returned by your eureka server and these have the same order as the ones I defined using application name as the predicate. I was able to fix this by setting the order for my route to -1.
Not sure if there is a better way to do this but at least I know hystrix is working.
Thanks
Maybe you should use this dependency:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>