小编aj1*_*984的帖子

基于 Zuul 的路由中的超时异常

我有以下设置,其中我的 Eureka 服务器正在运行,并且在 Eureka 中创建和注册的服务很少正在运行。所有服务呼叫的服务都在使用已负载平衡的休息模板进行,并且一切正常。

现在,我已经使用以下代码/属性将基于 Zuul 的路由引入到应用程序中 -

@SpringBootApplication
@EnableZuulProxy
public class ApiGatewayApplication {

    public static void main(String[] args) {
        SpringApplication.run(ApiGatewayApplication.class, args);
    }

    @Bean
     public CorsFilter corsFilter() {
         final UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource= new UrlBasedCorsConfigurationSource();
         final CorsConfiguration corsConfig = new CorsConfiguration();
         corsConfig.setAllowCredentials(true);
         corsConfig.addAllowedOrigin("*");
         corsConfig.addAllowedHeader("*");
         corsConfig.addAllowedMethod("OPTIONS");
         corsConfig.addAllowedMethod("HEAD");
         corsConfig.addAllowedMethod("GET");
         corsConfig.addAllowedMethod("PUT");
         corsConfig.addAllowedMethod("POST");
         corsConfig.addAllowedMethod("DELETE");
         corsConfig.addAllowedMethod("PATCH");
         urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfig);
         return new CorsFilter(urlBasedCorsConfigurationSource);
     }
}
Run Code Online (Sandbox Code Playgroud)

有了这个,我的路由工作得非常好,但是现在有一个服务需要接近 12 秒的执行时间,而且我的业务要求禁止打入较小的调用。

这会导致 Zuul 中的超时异常。

下面是我的 .yml 文件 -

ribbon:
  ConnectTimeout: 60000
  ReadTimeout: 600000
zuul:
  host:
    socket-timeout-millis: 60000
hystrix:
    command:
        default:
            execution: …
Run Code Online (Sandbox Code Playgroud)

java spring hystrix spring-cloud netflix-zuul

5
推荐指数
1
解决办法
9609
查看次数

Spring云配置客户端属性未得到解决

我对Spring Cloud和Spring外部配置的概念很陌生,实际上是昨天开始的.

我创建了一个Config Server从本地Git存储库中挑选配置,一个微服务也是配置客户端和一个Eureka驱动的服务发现服务器.

以下是我主要从互联网上的各种资源中借用的代码 -

配置服务器 - application.yml:

server:
  port: 8888

spring:
  cloud:
    config:
      server:
        git:
          uri: file:///${user.home}/config-repo
Run Code Online (Sandbox Code Playgroud)

配置服务器 - 主类(引导程序)

@EnableConfigServer
@SpringBootApplication
public class CloudConfigServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(CloudConfigServerApplication.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

config-repo是我机器上的本地git repo,并且有一个.yml文件,其名称为config client application,即authmanager.yml

eureka:
    client:
        serviceUrl:
            defaultZone: http://127.0.0.1:8761/eureka/
        healthcheck:
            enabled: true
        lease:
            duration: 5
spring:
    application:
        data:   
            mongodb:
                host: localhost
                port: 27017
                database: edc_mc
logging:
    level:
        org.exampledriven.eureka.customer.shared.CustomerServiceFeignClient: FULL
Run Code Online (Sandbox Code Playgroud)

现在运行配置服务器后,下面是端点http:// localhost:8888/authmanager/default的输出 -

{"name":"authmanager","profiles":["default"],"label":"master","version":"0ca6ca7b4502b9bb6ce1bf8efeb25516682cf79a","propertySources":[{"name":"file:///C:\\Users\\username/config-repo/authmanager.yml","source":{"eureka.client.serviceUrl.defaultZone":"http://127.0.0.1:8761/eureka/","eureka.client.healthcheck.enabled":true,"eureka.client.lease.duration":5,"spring.application.data.mongodb.host":"localhost","spring.application.data.mongodb.port":27017,"spring.application.data.mongodb.database":"db_name","logging.level.org.exampledriven.eureka.customer.shared.CustomerServiceFeignClient":"FULL"}}]}
Run Code Online (Sandbox Code Playgroud)

微服务+配置客户端代码 -

bootstrap.yml -

server:
  port: 9097

spring: …
Run Code Online (Sandbox Code Playgroud)

spring-boot spring-cloud spring-cloud-netflix spring-cloud-config

4
推荐指数
1
解决办法
5627
查看次数

无法将我的 Spring boot 应用程序打包为可运行的 fat Jar

我对 Spring boot 有点陌生,下面是我的应用程序的 POM/Java 文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.aj.stuff.install</groupId>
    <artifactId>MyProject</artifactId>
    <version>0.0.1</version>
    <packaging>jar</packaging>

    <name>Some-Name</name>
    <description>Some Stuff</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.1.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>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
        <finalName>MyProject</finalName>
    </build>

</project>
Run Code Online (Sandbox Code Playgroud)

主要的java应用程序代码片段如下 -

@SpringBootApplication
public class MyApplication {

    public static void main(String[] args) throws IOException, InterruptedException {
        SpringApplication.run(MyApplication.class, args);
... …
Run Code Online (Sandbox Code Playgroud)

java spring maven spring-boot

2
推荐指数
1
解决办法
6950
查看次数