Support
Quality
Security
License
Reuse
kandi has reviewed spring-cloud-netflix and discovered the below as its top functions. This is intended to give you an instant insight into spring-cloud-netflix implemented functionality, and help decide if they suit your requirements.
1. Features
2. Building 2.1. Basic Compile and Test 2.2. Documentation 2.3. Working with the code 2.3.1. Activate the Spring Maven profile 2.3.2. Importing into eclipse with m2eclipse 2.3.3. Importing into eclipse without m2eclipse
3. Contributing 3.1. Sign the Contributor License Agreement 3.2. Code of Conduct 3.3. Code Conventions and Housekeeping 3.4. Checkstyle 3.4.1. Checkstyle configuration 3.5. IDE setup 3.5.1. Intellij IDEA 3.6. Duplicate Finder 3.6.1. Duplicate Finder configuration
4. License
Service Discovery: Eureka instances can be registered and clients can discover the instances using Spring-managed beans
Service Discovery: an embedded Eureka server can be created with declarative Java configuration
Use the Spring Framework code format conventions. If you use Eclipse you can import formatter settings using the eclipse-code-formatter.xml file from the Spring Cloud Build project. If using IntelliJ, you can use the Eclipse Code Formatter Plugin to import the same file.
Make sure all new .java files to have a simple Javadoc class comment with at least an @author tag identifying you, and preferably at least a paragraph on what the class is for.
Add the ASF license header comment to all new .java files (copy from existing files in the project)
Add yourself as an @author to the .java files that you modify substantially (more than cosmetic changes).
Add some Javadocs and, if you change the namespace, some XSD doc elements.
A few unit tests would help a lot as well — someone has to do it.
If no-one else is using your branch, please rebase it against the current master (or other target branch in the main project).
When writing a commit message please follow these conventions, if you are fixing an existing issue please add Fixes gh-XXXX at the end of the commit message (where XXXX is the issue number).
Default Checkstyle rules
File header setup
Default suppression rules
Default Checkstyle rules
File header setup
Default suppression rules
Project defaults for Intellij that apply most of Checkstyle rules
Project style conventions for Intellij that apply most of Checkstyle rules
checkstyle.header.file - please point it to the Spring Cloud Build’s, spring-cloud-build-tools/src/main/resources/checkstyle-header.txt file either in your cloned repo or via the raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/main/resources/checkstyle-header.txt URL.
checkstyle.suppressions.file - default suppressions. Please point it to the Spring Cloud Build’s, spring-cloud-build-tools/src/checkstyle/checkstyle-suppressions.xml file either in your cloned repo or via the raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/checkstyle/checkstyle-suppressions.xml URL.
checkstyle.additional.suppressions.file - this variable corresponds to suppressions in your local project. E.g. you’re working on spring-cloud-contract. Then point to the project-root/src/checkstyle/checkstyle-suppressions.xml folder. Example for spring-cloud-contract would be: /home/username/spring-cloud-contract/src/checkstyle/checkstyle-suppressions.xml.
default
$ ./mvnw install
Zuul unable to route to application registered in eureka server
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
<version>3.1.0</version>
</dependency>
server:
port: 8082
spring:
application:
name: gateway
cloud:
gateway:
discovery:
locator:
enabled: true
lower-case-service-id: true
routes:
- id: game
uri: lb://game
predicates:
- Path=/game/**
- id: trend
uri: lb://trend
predicates:
- Path=/trend/**
eureka:
client:
serviceURL:
defaultZone: http://localhost:8761/eureka
-----------------------
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
<version>3.1.0</version>
</dependency>
server:
port: 8082
spring:
application:
name: gateway
cloud:
gateway:
discovery:
locator:
enabled: true
lower-case-service-id: true
routes:
- id: game
uri: lb://game
predicates:
- Path=/game/**
- id: trend
uri: lb://trend
predicates:
- Path=/trend/**
eureka:
client:
serviceURL:
defaultZone: http://localhost:8761/eureka
Maven: Classpath dependencies and starters?
<dependencies>
(... Other dependencies ...)
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<version>3.0.3</version>
</dependency>
(... Other dependencies ...)
</dependencies>
How to inject custom Http client to Spring Cloud openfeign?
@Bean
public CloseableHttpClient client() {
CloseableHttpClient httpClient=null;
try {
//... Skipping code for brevity.
//here creating "sslSocketFactory" used in the HttpClient builder below
httpClient = HttpClients.custom().setSSLSocketFactory(sslSocketFactory)
.setMaxConnTotal(10)
.setMaxConnPerRoute(10)
.build();
}catch(IOException | KeyManagementException | UnrecoverableKeyException | NoSuchAlgorithmException | KeyStoreException | CertificateException e) {
System.err.println("Exception during creation of HttpClient. : "+e.getMessage());
}
return httpClient;
}
@Bean
public feign.Client client() {
feign.Client client=null;
try {
//... Skipping code for brevity.
//here creating "sslSocketFactory" used in the HttpClient builder below
client = new Client.Default(sslSocketFactory, new DefaultHostnameVerifier());
}catch(IOException | KeyManagementException | UnrecoverableKeyException | NoSuchAlgorithmException | KeyStoreException | CertificateException e) {
System.err.println("Exception during creation of HttpClient. : "+e.getMessage());
}
}
-----------------------
@Bean
public CloseableHttpClient client() {
CloseableHttpClient httpClient=null;
try {
//... Skipping code for brevity.
//here creating "sslSocketFactory" used in the HttpClient builder below
httpClient = HttpClients.custom().setSSLSocketFactory(sslSocketFactory)
.setMaxConnTotal(10)
.setMaxConnPerRoute(10)
.build();
}catch(IOException | KeyManagementException | UnrecoverableKeyException | NoSuchAlgorithmException | KeyStoreException | CertificateException e) {
System.err.println("Exception during creation of HttpClient. : "+e.getMessage());
}
return httpClient;
}
@Bean
public feign.Client client() {
feign.Client client=null;
try {
//... Skipping code for brevity.
//here creating "sslSocketFactory" used in the HttpClient builder below
client = new Client.Default(sslSocketFactory, new DefaultHostnameVerifier());
}catch(IOException | KeyManagementException | UnrecoverableKeyException | NoSuchAlgorithmException | KeyStoreException | CertificateException e) {
System.err.println("Exception during creation of HttpClient. : "+e.getMessage());
}
}
Jhipster Spring Boot 2 instances of a microservice on different databases
java -Dspring.profiles.active=dev -Dserver.port=7040 -jar microservice-0.0.1-SNAPSHOT.jar -Dspring-boot.run.arguments= --hazelcast.port=12741 --APP_INSTANCE_NAME=microservice --APP_NAME=Microservice --APP_CLIENT_NAME='MicroserviceApp' --mainflux.broker=10.172.192.26 --APP_SWAGGER_TITLE='Microservice API' --APP_SWAGGER_DESC='Microservice API documentation'
eureka:
client:
enabled: true
healthcheck:
enabled: true
fetch-registry: true
register-with-eureka: true
instance-info-replication-interval-seconds: 10
registry-fetch-interval-seconds: 10
instance:
appname: ${APP_INSTANCE_NAME:microservice}
instanceId: ${APP_INSTANCE_NAME:microservice}:${spring.application.instance-id:${random.value}}
lease-renewal-interval-in-seconds: 5
lease-expiration-duration-in-seconds: 10
status-page-url-path: ${management.endpoints.web.base-path}/info
health-check-url-path: ${management.endpoints.web.base-path}/health
metadata-map:
zone: primary # This is needed for the load balancer
profile: ${spring.profiles.active}
version: #project.version#
git-version: ${git.commit.id.describe:}
git-commit: ${git.commit.id.abbrev:}
git-branch: ${git.branch:}
...
...
...
-----------------------
java -Dspring.profiles.active=dev -Dserver.port=7040 -jar microservice-0.0.1-SNAPSHOT.jar -Dspring-boot.run.arguments= --hazelcast.port=12741 --APP_INSTANCE_NAME=microservice --APP_NAME=Microservice --APP_CLIENT_NAME='MicroserviceApp' --mainflux.broker=10.172.192.26 --APP_SWAGGER_TITLE='Microservice API' --APP_SWAGGER_DESC='Microservice API documentation'
eureka:
client:
enabled: true
healthcheck:
enabled: true
fetch-registry: true
register-with-eureka: true
instance-info-replication-interval-seconds: 10
registry-fetch-interval-seconds: 10
instance:
appname: ${APP_INSTANCE_NAME:microservice}
instanceId: ${APP_INSTANCE_NAME:microservice}:${spring.application.instance-id:${random.value}}
lease-renewal-interval-in-seconds: 5
lease-expiration-duration-in-seconds: 10
status-page-url-path: ${management.endpoints.web.base-path}/info
health-check-url-path: ${management.endpoints.web.base-path}/health
metadata-map:
zone: primary # This is needed for the load balancer
profile: ${spring.profiles.active}
version: #project.version#
git-version: ${git.commit.id.describe:}
git-commit: ${git.commit.id.abbrev:}
git-branch: ${git.branch:}
...
...
...
I am getting this error java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal
<dependency>
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
<version>2.7.2</version>
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
<exclusions>
<exclusion>
<artifactId>xml-apis</artifactId>
<groupId>xml-apis</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>jaxen</groupId>
<artifactId>jaxen</artifactId>
<version>1.2.0</version>
<exclusions>
<exclusion>
<artifactId>xerces</artifactId>
<groupId>xercesImpl</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.0.0</version>
<exclusions>
<exclusion>
<artifactId>xml-apis</artifactId>
<groupId>xml-apis</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.io7m.xom</groupId>
<artifactId>xom</artifactId>
<version>1.2.10</version>
<exclusions>
<exclusion>
<artifactId>xerces</artifactId>
<groupId>xercesImpl</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.4.01</version>
</dependency>
-----------------------
<dependency>
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
<version>2.7.2</version>
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
<exclusions>
<exclusion>
<artifactId>xml-apis</artifactId>
<groupId>xml-apis</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>jaxen</groupId>
<artifactId>jaxen</artifactId>
<version>1.2.0</version>
<exclusions>
<exclusion>
<artifactId>xerces</artifactId>
<groupId>xercesImpl</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.0.0</version>
<exclusions>
<exclusion>
<artifactId>xml-apis</artifactId>
<groupId>xml-apis</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.io7m.xom</groupId>
<artifactId>xom</artifactId>
<version>1.2.10</version>
<exclusions>
<exclusion>
<artifactId>xerces</artifactId>
<groupId>xercesImpl</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.4.01</version>
</dependency>
Spring Boot App doesn't start when the first eureka server is down
@Slf4j
@Configuration
public class EurekaMultiClientBoostrapConfig {
@Bean
@Primary
public RestTemplateEurekaHttpClient configDiscoveryRestTemplateEurekaHttpClient(EurekaClientConfigBean config) {
List<String> urls = EndpointUtils.getServiceUrlsFromConfig(config,
EurekaClientConfigBean.DEFAULT_ZONE, true);
for (String url : urls) {
try {
RestTemplateEurekaHttpClient client = (RestTemplateEurekaHttpClient) new RestTemplateTransportClientFactory()
.newClient(new DefaultEndpoint(url));
client.getApplications(config.getRegion());
log.info("Registered on Eureka host '{}' is successful.", url);
return client;
} catch (Exception e) {
log.warn("Eureka host '{}' is unavailable(reason: {})", url, e.getMessage());
}
}
throw new IllegalStateException("Failed to register on any eureka host.");
}
org.springframework.cloud.bootstrap.BootstrapConfiguration=your.app.package.EurekaMultiClientBoostrapConfig
-----------------------
@Slf4j
@Configuration
public class EurekaMultiClientBoostrapConfig {
@Bean
@Primary
public RestTemplateEurekaHttpClient configDiscoveryRestTemplateEurekaHttpClient(EurekaClientConfigBean config) {
List<String> urls = EndpointUtils.getServiceUrlsFromConfig(config,
EurekaClientConfigBean.DEFAULT_ZONE, true);
for (String url : urls) {
try {
RestTemplateEurekaHttpClient client = (RestTemplateEurekaHttpClient) new RestTemplateTransportClientFactory()
.newClient(new DefaultEndpoint(url));
client.getApplications(config.getRegion());
log.info("Registered on Eureka host '{}' is successful.", url);
return client;
} catch (Exception e) {
log.warn("Eureka host '{}' is unavailable(reason: {})", url, e.getMessage());
}
}
throw new IllegalStateException("Failed to register on any eureka host.");
}
org.springframework.cloud.bootstrap.BootstrapConfiguration=your.app.package.EurekaMultiClientBoostrapConfig
How to add dynamic header values to feign-client through Feign interceptor from current request?
circuitBreakerFactory
.create("createUserProfile").run(
() -> {
String resp = callerClient.callExternalService();
return resp;
}, exception -> {
logger.info(exception.getMessage());
}
);
@Bean
DispatcherServlet dispatcherServlet() {
DispatcherServlet servlet = new DispatcherServlet();
servlet.setThreadContextInheritable(true);
return servlet;
}
-----------------------
circuitBreakerFactory
.create("createUserProfile").run(
() -> {
String resp = callerClient.callExternalService();
return resp;
}, exception -> {
logger.info(exception.getMessage());
}
);
@Bean
DispatcherServlet dispatcherServlet() {
DispatcherServlet servlet = new DispatcherServlet();
servlet.setThreadContextInheritable(true);
return servlet;
}
Zuul routing the requests through an external proxy server
test2:
path: /proxied-test2/**
serviceId: test2
url: http://my.api.server.com
-Dhttp.proxyHost=localhost -Dhttp.proxyPort=8888
zuul:
routes
test:
path: /test/**
serviceId: test
url: http://my.api.server.com
test2:
path: /test2/**
serviceId: test2
url: http://localhost:9200/proxied-test2/
-Dhttp.proxyHost=localhost -Dhttp.proxyPort=8888
-----------------------
test2:
path: /proxied-test2/**
serviceId: test2
url: http://my.api.server.com
-Dhttp.proxyHost=localhost -Dhttp.proxyPort=8888
zuul:
routes
test:
path: /test/**
serviceId: test
url: http://my.api.server.com
test2:
path: /test2/**
serviceId: test2
url: http://localhost:9200/proxied-test2/
-Dhttp.proxyHost=localhost -Dhttp.proxyPort=8888
-----------------------
test2:
path: /proxied-test2/**
serviceId: test2
url: http://my.api.server.com
-Dhttp.proxyHost=localhost -Dhttp.proxyPort=8888
zuul:
routes
test:
path: /test/**
serviceId: test
url: http://my.api.server.com
test2:
path: /test2/**
serviceId: test2
url: http://localhost:9200/proxied-test2/
-Dhttp.proxyHost=localhost -Dhttp.proxyPort=8888
-----------------------
test2:
path: /proxied-test2/**
serviceId: test2
url: http://my.api.server.com
-Dhttp.proxyHost=localhost -Dhttp.proxyPort=8888
zuul:
routes
test:
path: /test/**
serviceId: test
url: http://my.api.server.com
test2:
path: /test2/**
serviceId: test2
url: http://localhost:9200/proxied-test2/
-Dhttp.proxyHost=localhost -Dhttp.proxyPort=8888
How to pass Pageable to Feign Client in POST Request with additional @RequestBody
@PostMapping("/search")
public Page<MeasureDto> searchMeasures(@RequestBody MeasureDto example, @RequestParam(required = true) Integer page) {
// PageRequest.Of(numberPage, quantityRegisters) will send a Pageable, in this case bellow, number of page + number of records
measureService.getMeasurePageable(example, PageRequest.of(page, 10));
}
-----------------------
@PostMapping("/search")
public Page<HelloDto> searchHellos(@RequestHeader("apiKey") String apiKey, @RequestBody HelloDto example, @SpringQueryMap Pageable pageable);
package org.springframework.cloud.netflix.zuul does not exist
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-core</artifactId>
<version>1.3.0.RELEASE</version>
</dependency>
</dependencies>
QUESTION
Spring Boot Microservice zuul Forwarding error
Asked 2022-Mar-22 at 12:00I have created micro service using spring boot and implment zuul proxy so when I call url via zuul proxy and somehow my service is down I get com.netflix.zuul.exception.ZuulException
com.netflix.zuul.exception.ZuulException: Forwarding error at org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.handleException(RibbonRoutingFilter.java:198) ~[spring-cloud-netflix-zuul-2.2.1.RELEASE.jar:2.2.1.RELEASE] at org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.forward(RibbonRoutingFilter.java:173) ~[spring-cloud-netflix-zuul-2.2.1.RELEASE.jar:2.2.1.RELEASE] at org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.run(RibbonRoutingFilter.java:119) ~[spring-cloud-netflix-zuul-2.2.1.RELEASE.jar:2.2.1.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:166) [spring-webmvc-5.2.4.RELEASE.jar:5.2.4.RELEASE] at org.springframework.cloud.netflix.zuul.web.ZuulController.handleRequest(ZuulController.java:45) [spring-cloud-netflix-zuul-2.2.1.RELEASE.jar:2.2.1.RELEASE] at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:52) [spring-webmvc-5.2.4.RELEASE.jar:5.2.4.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040) [spring-webmvc-5.2.4.RELEASE.jar:5.2.4.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) [spring-webmvc-5.2.4.RELEASE.jar:5.2.4.RELEASE] at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) [spring-webmvc-5.2.4.RELEASE.jar:5.2.4.RELEASE] at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) [spring-webmvc-5.2.4.RELEASE.jar:5.2.4.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:634) [tomcat-embed-core-9.0.31.jar:9.0.31] at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) [spring-webmvc-5.2.4.RELEASE.jar:5.2.4.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) [tomcat-embed-core-9.0.31.jar:9.0.31]
ANSWER
Answered 2022-Mar-22 at 12:00Zuul API gateway has been deprecated and now in maintenance mode. so it not recommended to use it.
You should use latest Spring Cloud Gatway in your project. if you want to use gateway
learn more about spring cloud gateway here :https://www.baeldung.com/spring-cloud-gateway
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Save this library and start creating your kit
Explore Related Topics
Save this library and start creating your kit