标签: spring-cloud

Spring Cloud Config Server无法在启动时找到PropertySource

当我启动Spring Cloud Config Server时出现以下错误.

Could not locate PropertySource: I/O error on GET request for "http://localhost:8888/configserver/default/master":Connection refused; nested exception is java.net.ConnectException: Connection refused
Run Code Online (Sandbox Code Playgroud)

但是,当我在浏览器中点击该URL时,它存在且配置服务器正在运行.到底是怎么回事?

application.yml

server:
  port: 8888
management:
  context-path: /admin
logging:
  level:
    com.netflix.discovery: 'OFF'
    org.springframework.cloud: 'DEBUG'
spring:
  cloud:
    config:
      server:
        git:
          uri: file:/home/dev/configs     
Run Code Online (Sandbox Code Playgroud)

bootstrap.yml

spring:
  application:
    name: configserver
Run Code Online (Sandbox Code Playgroud)

spring-boot spring-cloud

11
推荐指数
1
解决办法
3万
查看次数

为什么ZUUL强制执行SEMAPHORE隔离以执行其Hystrix命令?

我注意到Spring-Cloud ZUUL强制执行隔离到SEMAPHORE而不是THREAD默认值(根据Netflix的推荐).

评论org.springframework.cloud.netflix.zuul.filters.route.RibbonCommand说:

我们希望默认为信号量隔离,因为这包含了另外两个已经线程隔离的命令

但我仍然没有得到它:-(那两个其他命令是什么?

以这种方式配置,Zuul只能调整加载但不允许超时并让客户端离开.简而言之,即使Hystrix超时设置为1000毫秒,只有在转发到链中的服务的调用返回时(或者由于例如ReadTimeout而超时),才会释放客户端.

我试图通过覆盖配置强制THREAD隔离(不幸的是,每个服务,因为在代码中强制默认),一切似乎按预期工作.但是,如果没有正确理解其含义,我并不热衷于这样做 - 当然关于代码中的注释以及Spring的Zuul版本采用的默认值.

有人可以提供更多信息吗?谢谢

spring-cloud netflix-zuul

11
推荐指数
1
解决办法
5916
查看次数

Spring云:功能区和HTTPS

我们希望将HTTPS用于基于Feign和Ribbon的微服务通信.这些服务基于spring boot并且正确设置了tomcat.实例已在Eureka上的HTTPS URL和securePort上注册.但是,当我们通过Feign调用另一个微服务时,底层功能区无法识别协议并回退到HTTP.我可以通过将协议添加到FeignClient注释来解决这个问题,如下所示:

    @FeignClient("https://users")
Run Code Online (Sandbox Code Playgroud)

但似乎Zuul代理和Hystrix/Turbine也在内部使用Ribbon具有相同的HTTP回退问题.有没有办法集中配置Ribbon以使用HTTPS作为默认值或使用注册的eureka实例的securePort设置?

Eureka实例配置:

eureka.instance.hostname=localhost
eureka.instance.securePort = ${server.port}
eureka.instance.securePortEnabled = true  
eureka.instance.nonSecurePortEnabled = false 
eureka.instance.metadataMap.hostname = ${eureka.instance.hostname}
eureka.instance.metadataMap.securePort = ${server.port}
eureka.instance.homePageUrl = https://${eureka.instance.hostname}:${server.port}/
eureka.instance.statusPageUrl = https://${eureka.instance.hostname}:${server.port}/admin/info
Run Code Online (Sandbox Code Playgroud)

通过这些设置,它在Eureka中看起来就像服务在HTTPS上运行一样.Zuul代理运行正常,但使用HTTP URL来调用服务.您必须通过在密钥库中提供服务器证书来在Spring Boots嵌入式Tomcat中启用SSL:

server.ssl.key-store=server.jks
server.ssl.key-store-password=<pw>
server.ssl.keyStoreType=jks
server.ssl.keyAlias=tomcat
server.ssl.key-password=<pw> 
Run Code Online (Sandbox Code Playgroud)

Tomcat只运行在HTTPS上,HTTP端口被阻止,但比我得到的:localhost:8081 failed to respond因为HTTP URL用于调用服务.通过设置ribbon.IsSecure=true用户服务URL正确生成,但Ribbon负载均衡器无法在Eureka中查找用户服务:Load balancer does not have available server for client: users.我users.ribbon.IsSecure=trueaslo 试图只在zuul代理中设置,但仍然得到相同的错误.

Caused by: com.netflix.client.ClientException: Load balancer does not have available server for client: user
at com.netflix.loadbalancer.LoadBalancerContext.getServerFromLoadBalancer(LoadBalancerContext.java:468)
at com.netflix.loadbalancer.reactive.LoadBalancerCommand$1.call(LoadBalancerCommand.java:184) …
Run Code Online (Sandbox Code Playgroud)

spring spring-boot spring-cloud

11
推荐指数
1
解决办法
1万
查看次数

Spring Cloud Eureka与配置服务器

使用Eureka Server运行配置服务器时,建议的配置是什么?Config Server应该是Eureka的客户吗?或者Eureka是否应该依赖Config Server属性进行配置?或者两个都好吗?

java spring spring-cloud netflix-eureka spring-cloud-config

11
推荐指数
3
解决办法
7074
查看次数

模拟Eureka Feign客户进行单元测试

我正在使用spring cloud的eureka并假装在一些服务之间进行通信(比方说A和B).现在我喜欢单一测试单个服务的服务层(A).问题是,该服务(A)正在使用假装客户端来请求其他服务的一些信息(B).

在没有任何特殊配置的情况下运行unittes会引发以下异常:java.lang.RuntimeException: com.netflix.client.ClientException: Load balancer does not have available server for client: service-b=>但我不希望任何服务器运行.

我的问题是:有没有办法嘲笑假装客户端,所以我可以在不运行eureka实例和服务(B)的情况下对我的服务(A)进行单元测试?

编辑:我最终为假装客户端创建了一个存根.存根被标记为主要组件,以强制spring在我的测试中实例化存根.
这是我提出的解决方案.

//the feign client
@FeignClient("user") 
public interface UserClient { 
    UserEntity getUser(); 
}

//the implementation i use for the tests 
@Component 
@Primary //mark as primary implementation
public class UserClientTestImpl implements UserClient { 
    @Override public UserEntity getUser() { 
        return someKindOfUser; 
    } 
}
Run Code Online (Sandbox Code Playgroud)

unit-testing spring-cloud netflix-feign netflix-eureka

11
推荐指数
2
解决办法
2万
查看次数

为Hystrix-AMQP生成的LOGS太多

所以我将Hystrix-AMQP的依赖项添加到我的服务中,日志文件变得疯狂,它只是继续记录指标的东西.我需要那个罐子才能将它与涡轮AMQP一起使用.

这是我在hystrix的gradle中所拥有的: -

compile         ("org.springframework.cloud:spring-cloud-starter-hystrix:1.0.6.RELEASE")
compile         ('org.springframework.cloud:spring-cloud-starter-bus-amqp:1.0.6.RELEASE')
compile         ('org.springframework.cloud:spring-cloud-netflix-hystrix-amqp:1.0.7.RELEASE')
compile         ('com.netflix.hystrix:hystrix-javanica:1.5.2')
Run Code Online (Sandbox Code Playgroud)

这是继续在我的日志中生成它继续运行: -

   2016-05-03 13:49:14.698 INFO [LogMessage=Starting span: MilliSpan(begin=1462308554698, end=0, name=execution(HystrixStreamTask.sendMetrics()), traceId=21825112-0c71-4c6a-a9ca-51b11a21e4e5, parents=[], spanId=053946b5-7287-41f4-8579-d048655f41ea, remote=false, annotations={}, processId=null, timelineAnnotations=[])]
2016-05-03 13:49:14.698 INFO  [LogMessage=Continued span: MilliSpan(begin=1462308554698, end=0, name=execution(HystrixStreamTask.sendMetrics()), traceId=21825112-0c71-4c6a-a9ca-51b11a21e4e5, parents=[], spanId=053946b5-7287-41f4-8579-d048655f41ea, remote=false, annotations={}, processId=null, timelineAnnotations=[])]
2016-05-03 13:49:14.698 INFO  [LogMessage=Stopped span: MilliSpan(begin=1462308554698, end=1462308554698, name=execution(HystrixStreamTask.sendMetrics()), traceId=21825112-0c71-4c6a-a9ca-51b11a21e4e5, parents=[], spanId=053946b5-7287-41f4-8579-d048655f41ea, remote=false, annotations={/messaging/headers/id=e1cc5042-1a5c-e3f9-6f3c-de936d1aa959, /messaging/headers/timestamp=1462308554698, /messaging/payload/type=java.lang.String, /messaging/payload/size=592}, processId=null, timelineAnnotations=[])]
2016-05-03 13:49:14.698 INFO  [LogMessage=Starting span: MilliSpan(begin=1462308554698, end=0, name=execution(HystrixStreamTask.gatherMetrics()), traceId=6cc342bb-9693-493a-8fa8-8a17c2ff06c3, parents=[], spanId=10cdee69-22f8-43ab-883f-3e09b29ab6fb, remote=false, annotations={}, processId=null, timelineAnnotations=[])]
2016-05-03 13:49:14.699 INFO [LogMessage=Continued …
Run Code Online (Sandbox Code Playgroud)

java netflix amqp hystrix spring-cloud

11
推荐指数
1
解决办法
484
查看次数

如何通过假装客户端使用基本身份验证保护的Restful Web服务

感谢您的时间.为简单起见,我创建了一个示例服务,如下所示:

@RestController
@RequestMapping("/")
public class ComputeController {

    @GetMapping("/add")
    public int add(@RequestParam("left") int left, @RequestParam("right") int right) {
        return left + right;
    }
}
Run Code Online (Sandbox Code Playgroud)

为了保护这个URL,我像这样配置spring-security:

management.security.enabled=true
security.user.name=admin
security.user.password=admin
Run Code Online (Sandbox Code Playgroud)

当我启动此服务并访问如下:

GET /add?left=100&right=11 HTTP/1.1
Authorization: ***** Hidden credentials *****
Host: localhost:7777
Connection: close
Run Code Online (Sandbox Code Playgroud)

这一切都很顺利.

在其他节点中,我通过netflix feign创建了一个"service-comsumer".这是一个Java接口.

@FeignClient(name = "API-GATEWAY", path = "/compute-service", fallback = ComputeServiceCircuitBreaker.class)
public interface ComputeServiceClient {

    @RequestMapping(path = "/add", method = RequestMethod.GET)
    public Integer add(@RequestParam("left") Integer left, @RequestParam("right") Integer right);
}
Run Code Online (Sandbox Code Playgroud)

但我不知道如何配置请求标题"授权".

任何的想法?再次感谢.

spring-security spring-cloud spring-cloud-netflix

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

使用Spring Boot假设客户端:RequestParam.value()在参数0上为空

我用Spring Boot创建了一个简单的Feign Client:

@FeignClient("spring-cloud-eureka-client")
public interface GreetingClient {
    @RequestMapping("/greeting")
    String greeting(@RequestParam String name);
}
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试启动一个应用程序时,我收到一个错误:

java.lang.IllegalStateException: RequestParam.value() was empty on parameter 0
Run Code Online (Sandbox Code Playgroud)

首先,我不明白是什么原因和谷歌搜索,但没有找到答案.几乎不可思议地我发现如果明确地写请求参数名称它是有效的:

@RequestParam("name") String name
Run Code Online (Sandbox Code Playgroud)

所以我的问题是:它是一个错误还是可以配置为不明确写入请求参数名称?

spring spring-cloud spring-cloud-feign

11
推荐指数
2
解决办法
8061
查看次数

Spring Cloud Gateway - 代理/转发URL的整个子部分

我正在使用Spring Cloud Gateway 2.0.0.M6测试一个简单的网关.我只想将一个URL转发到另一个带有**正则表达式的URL

示例1:/ integration/sbl/foo/bar => localhost:4178/a-integration/sbl/foo/bar

示例2:/ integration/sbl/baz/bad => localhost:4178/a-integration/sbl/baz/bad

到目前为止,我已经写了以下内容,但它只转发到http:// localhost:4178/a-integration /

 @Bean
public RouteLocator routeLocator(RouteLocatorBuilder builder) {
    String test = "http://localhost:4178/a-integration/";

    return builder.routes()
            .route("integration-test",
                    r -> r.path("/integration/sbl/**")
                            .uri(test)
            )
            .build();
}
Run Code Online (Sandbox Code Playgroud)

如何修复上述代码以启用此行为?

编辑

我根据下面的回答尝试了以下内容

String samtykke = "http://localhost:4178/";

return builder.routes()

        .route("samtykke", r -> r
                .path("/gb-integration/sbl/**")
                .filters(f -> f.rewritePath("/gb-integration/sbl/(?<segment>.*)", "/gb-samtykke-integration/${segment}"))
                .uri(samtykke))
        .build();
Run Code Online (Sandbox Code Playgroud)

我尝试了一个GET http:// localhost:4177/gb-integration/sbl/api/sbl/income /并预期http:// localhost:4178/gb-samtykke-integration/api/sbl/income / back但它没用.

输出说:

2018-02-23 09:46:35.197 TRACE 6364 --- [ctor-http-nio-2] o.s.c.g.h.p.RoutePredicateFactory        : Pattern "/gb-integration/sbl/**" matches against value …
Run Code Online (Sandbox Code Playgroud)

spring spring-boot spring-cloud spring-cloud-gateway

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

无法使用Spring Cloud与AWS SES连接

我使用Spring Boot做了一个非常简单的Maven项目。我正在尝试使用Spring Cloud与AWS SES连接。在运行项目时,出现以下错误:

未定义有效的实例ID

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cloud.aws.core.env.ResourceIdResolver.BEAN_NAME': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'stackResourceRegistryFactoryBean' defined in class path resource [org/springframework/cloud/aws/autoconfigure/context/ContextStackAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.aws.core.env.stack.config.StackResourceRegistryFactoryBean]: Factory method 'stackResourceRegistryFactoryBean' threw exception; nested exception is java.lang.IllegalArgumentException: No valid instance id defined
Run Code Online (Sandbox Code Playgroud)

我正在显示正在使用的文件片段:

pom.xml

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.3.RELEASE</version>
</parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions> …
Run Code Online (Sandbox Code Playgroud)

amazon-ses spring-boot spring-cloud

11
推荐指数
1
解决办法
3019
查看次数