标签: spring-cloud

使用Java而不是bootstrap.yml通过Eureka查找Spring Cloud Config Server

我正在尝试在我们的基础pom中构建代码,通过Eureka自动配置Spring Cloud Config服务器查找.我们这样做是为了避免模仿开发人员构建微服务的.yml属性.例如,我们想要java配置从这些属性触发的所有行为:

spring:
  application:
    name: MyMicroservice
  cloud:
    config:
      enabled: true
    server:
      prefix: /diagnostics/admin/config
    failFast: true
    discovery:
      enabled: true
      serviceId: echo

management:
  context-path: /diagnostics/admin

eureka:
  password: password
  client:
    serviceUrl:
      defaultZone: http://user:${eureka.password}@localhost:8761/eureka/
  instance:
    leaseRenewalIntervalInSeconds: 10
    statusPageUrlPath: /diagnostics/admin/info
    healthCheckUrlPath: /diagnostics/admin/health
Run Code Online (Sandbox Code Playgroud)

经过大量实验后,除了Eureka发现的配置服务器(导致没有覆盖的配置属性)之外,以下方法大部分都有效:

@Order(-1)
public class AdditionalBootstrapPropertySourceLocator implements PropertySourceLocator {

    @Override
    public PropertySource<?> locate(Environment environment) {
        Map<String, Object> theBootstrapYmlConfig = new HashMap<>();
        theBootstrapYmlConfig.put("spring.cloud.config.enabled", new Boolean(true));
        theBootstrapYmlConfig.put("spring.cloud.config.server.prefix", "/diagnostics/admin/config");
        theBootstrapYmlConfig.put("spring.cloud.config.failFast", new Boolean(true));
        theBootstrapYmlConfig.put("spring.cloud.config.discovery.enabled", new Boolean(true));
        theBootstrapYmlConfig.put("spring.cloud.config.discovery.serviceId", "echo");

        theBootstrapYmlConfig.put("management.context-path", "/diagnostics/admin");

        theBootstrapYmlConfig.put("eureka.client.serviceUrl.defaultZone", "http://user:password@localhost:8761/eureka/");
        theBootstrapYmlConfig.put("eureka.instance.leaseRenewalIntervalInSeconds", new Integer(10));
        theBootstrapYmlConfig.put("eureka.instance.statusPageUrlPath", "/diagnostics/admin/info"); …
Run Code Online (Sandbox Code Playgroud)

java spring-boot spring-cloud

6
推荐指数
1
解决办法
3136
查看次数

访问通过Zuul和Apache代理的资源服务器中的远程IP地址

为了安全检查,我需要在我的资源服务中访问用户的远程IP地址.这个资源服务是一个简单的最新Spring Boot应用程序,它使用我的Eureka服务器注册自己:

@SpringBootApplication
@EnableEurekaClient
public class ServletInitializer extends SpringBootServletInitializer {
    public static void main(final String[] args) {
        SpringApplication.run(ServletInitializer.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

我尤里卡服务器注册的所有服务都通过基于Angel.SR3我Zuul路由代理服务器的动态路由starter-zuul和starter-eureka:

@SpringBootApplication
@EnableZuulProxy
@EnableEurekaClient
public class RoutingProxyServer {
    public static void main(final String[] args) {
        SpringApplication.run(RoutingProxyServer.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

Zuul路由代理服务器还为下一步配置AJP连接器:

@Configuration
@ConditionalOnProperty("ajp.port")
public class TomcatAjpConfig extends TomcatWebSocketContainerCustomizer {
    @Value("${ajp.port}")
    private int port;

    @Override
    public void doCustomize(final TomcatEmbeddedServletContainerFactory tomcat) {
        super.doCustomize(tomcat);

        // Listen for AJP requests
        Connector ajp = new Connector("AJP/1.3");
        ajp.setPort(port);
        tomcat.addAdditionalTomcatConnectors(ajp);
    }
}
Run Code Online (Sandbox Code Playgroud)

对动态路由zuul代理的所有请求都通过Apache代理,以便在标准443端口上提供HTTPS: …

apache spring-security spring-cloud netflix-zuul

6
推荐指数
1
解决办法
5085
查看次数

可以在没有Eureka/Ribbon或其他Netflix OSS模块的情况下使用Hystrix

我们拥有一个拥有自己的API网关,服务发现和负载平衡的基础架构.但是出于弹性目的,我需要使用Hystrix.

  1. 使用spring cloud netflix,可以在没有 Eureka/Ribbon或其他Netflix OSS模块的情况下使用Hystrix(即断路器注释)吗?
  2. 对于断路器仪表板(即涡轮机和流聚合器),是否依赖于Eureka/Ribbon/Zuul?
  3. 可以在非弹簧启动应用中使用断路器注释吗?

netflix turbine hystrix spring-cloud netflix-eureka

6
推荐指数
1
解决办法
1887
查看次数

在spring-cloud环境中分布式Rabbitmq

我正在尝试使用以下组件基于当前的spring-cloud发布(主要是Netflix OSS)来设置分布式系统

  • 1个或多个云配置服务器
  • 1个或更多Eureka服务器
  • 使用Eureka和Config Server客户端的一项或多项服务

上面的设置很容易开始,但是一旦你开始研究设置,以便云配置服务器中的配置更改自动触发实际客户端的值的变化,事情开始变得更加复杂.

我的理解是,要使这样的功能工作,应该将spring-cloud-bus客户端引入服务,这些服务反过来将使用,目前唯一支持的实现,rabbitmq服务器(实际的rabbitmq二进制文件,而不是一些spring-boot应用程序,如eureka或Config服务器)允许Config服务器中的更改事件自动传播到客户端.

设置这样的系统听起来违反直觉,并且必须将地址硬编码到客户端中的rabbitmq服务器(即使一个人将保持Rabbitmq服务器的数量或多或少是静态的).

如何在Eureka服务发现服务器中注册rabbitmq服务器实例,以允许客户端在启动之前无需了解其位置即可找到它们?

鉴于rabbitmq不是spring-cloud组件,我似乎无法找到有关如何完成此操作的任何文档.实际上,关于如何将rabbitmq + eureka + spring-cloud-bus设置在一起的文档似乎很少.

rabbitmq spring-amqp spring-cloud netflix-eureka

6
推荐指数
1
解决办法
1474
查看次数

spring cloud - 我的jar外面的bootstrap.properties

我试图bootstrap.properties从我的罐子外面放置,所以它不会被其他开发人员错误地覆盖.你能在这里建议吗?

这是它的'内容 - 指向spring server config

# application name
spring.application.name=elixium
# The server entry point
spring.cloud.config.uri=http://localhost:8888
Run Code Online (Sandbox Code Playgroud)

java spring spring-cloud spring-cloud-config

6
推荐指数
1
解决办法
4462
查看次数

Zuul - > Eureka Server,基本身份验证问题

如果流程不包含基本授权,我可以点击该服务.

如果我使用基本授权,它会抛出"消息":"访问此资源需要完全身份验证"

以下是我的观察:

在ZuulFilter中,运行()方法,我得到request.getHeader("Authorization") - > Basic c29tOnNvbzz ==的值

但是一旦它到达Micro服务,我的价值就是'null',request.getHeader("Authorization") - > null

使用Spring Boot版本:1.4.0.RELEASE

This is my flow:
------------------

Zuul -> Service Discovery (Eureka Server) -> Service
Run Code Online (Sandbox Code Playgroud)

请帮忙,不确定Authorization标头消失的位置.

Eureka Server yml file:
-------------------------
server.port:4001
eureka.instance.hostname=localhost
eureka.client.fetch-registry:false
eureka.client.register-with-eureka:false
eureka.client.serviceUrl.defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
eureka.client.healthcheck.enabled=true

Zuul yml file:
-----------------
server:
  port: 8765
info:
  component: Edge Server
eureka:
  instance:
    leaseRenewalIntervalInSeconds: 3
    metadataMap:
      instanceId: ${spring.application.name}:${random.value}
  client:
    # Default values comes from org.springframework.cloud.netflix.eurek.EurekaClientConfigBean
    registryFetchIntervalSeconds: 5
    instanceInfoReplicationIntervalSeconds: 5
    initialInstanceInfoReplicationIntervalSeconds: 5

endpoints:
  restart:
    enabled: true
  shutdown:
    enabled: true
  health: …
Run Code Online (Sandbox Code Playgroud)

spring-boot spring-cloud netflix-eureka netflix-zuul

6
推荐指数
1
解决办法
3404
查看次数

当实例关闭并转发到其他可用实例时,Spring cloud Zuul重试

使用'Camden.SR5'来实现spring-cloud-dependencies,使用spring boot'1.5.2.RELEASE'.

在我目前的设置中,我有

  • 尤里卡服务器
  • 配置服务器(在随机端口上运行)
  • zuul网关服务器
  • 和2个服务实例(在随机端口上运行)

所有这些实例都成功注册了Eureka.

在此输入图像描述

当所有服务都在运行时,负载均衡通过zuul正确完成,没有任何问题.

当一个实例被杀死时,Zuul仍在尝试使用相同的服务来完成请求.但是,如果在关闭实例后等到eureka注册表被提取,请求将与其他"UP"实例一起完成.

    2017-03-07 19:57:41.409 DEBUG 26658 --- [nio-5555-exec-3] c.n.l.reactive.LoadBalancerCommand       : Got error org.apache.http.conn.HttpHostConnectException: Connect to 10.99.4.151:64381 [/10.99.4.151] failed: Connection refused when executed on server 10.99.4.151:64381
2017-03-07 19:57:41.420 DEBUG 26658 --- [nio-5555-exec-3] com.netflix.hystrix.AbstractCommand      : Error executing HystrixCommand.run(). Proceeding to fallback logic ...

com.netflix.client.ClientException: null
    at com.netflix.client.AbstractLoadBalancerAwareClient.executeWithLoadBalancer(AbstractLoadBalancerAwareClient.java:123) ~[ribbon-loadbalancer-2.2.0.jar:2.2.0]
    at com.netflix.client.AbstractLoadBalancerAwareClient.executeWithLoadBalancer(AbstractLoadBalancerAwareClient.java:81) ~[ribbon-loadbalancer-2.2.0.jar:2.2.0]
    at org.springframework.cloud.netflix.zuul.filters.route.support.AbstractRibbonCommand.run(AbstractRibbonCommand.java:96) ~[spring-cloud-netflix-core-1.2.5.RELEASE.jar:1.2.5.RELEASE]
    at org.springframework.cloud.netflix.zuul.filters.route.support.AbstractRibbonCommand.run(AbstractRibbonCommand.java:42) ~[spring-cloud-netflix-core-1.2.5.RELEASE.jar:1.2.5.RELEASE]
Run Code Online (Sandbox Code Playgroud)
    at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:75) ~[httpclient-4.5.3.jar:4.5.3]
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142) ~[httpclient-4.5.3.jar:4.5.3]
    ... 162 common frames omitted

2017-03-07 19:57:41.425 DEBUG 26658 --- [nio-5555-exec-3] …
Run Code Online (Sandbox Code Playgroud)

microservices spring-cloud netflix-zuul spring-cloud-feign spring-cloud-netflix

6
推荐指数
1
解决办法
3984
查看次数

春云假装hystrix后退不起作用

弹簧启动版本1.3.8.RELEASE和云版本'Brixton.SR'相同的代码工作正常.但是'1.5.2.RELEASE'和'Dalston.RC1'不起作用.

例外

HTTP状态500 - 请求处理失败; 嵌套异常是java.lang.RuntimeException:com.netflix.client.ClientException:负载均衡器没有客户端的可用服务器:math-service

java spring hystrix spring-cloud feign

6
推荐指数
1
解决办法
2801
查看次数

Spring库存有EOL(寿命结束)和EOVS(供应商支持终止)日期吗?

是否有任何EOL(寿命结束)和EOVS(供应商支持的结束)日期为春季启动,春季云,春季会议等春季文库?如果是,我在哪里可以找到每个版本的库的这些信息?

eol spring-boot spring-session spring-cloud

6
推荐指数
1
解决办法
2786
查看次数

Spring Cloud Function是否适合REST API?如何访问GET路径参数?

我是WebFlux和Serverless的新手。我正在尝试通过AWS API网关将REST API创建为无服务器。

该流程将是API网关-> Lambda-> DynamoDB

为了实现API流程,Spring Cloud Function是最佳选择吗?我发现aws-serverless-java-container无缝地完成了这项工作(将事件转换为http请求/响应的包装器)

我浏览了http://cloud.spring.io/spring-cloud-function/single/spring-cloud-function.html上的文档以及https://github.com/spring-cloud/上的一些示例弹簧云功能。但是,我仍然不确定是否可以使用Spring Cloud Function实现API风格。

@Bean
//How path or query params can be mapped?
public Function<Flux<String>, Flux<String>> getEmployeeDetails() {
 // business logic goes here
}
Run Code Online (Sandbox Code Playgroud)

在上面的代码片段中,如何实现GET请求/响应模型。如果我的端点具有/ {dept} / {employee} / {name},那么Spring cloud函数如何在GET请求中接受路径参数?

任何指针都会有所帮助。

spring spring-cloud aws-lambda spring-webflux serverless

6
推荐指数
1
解决办法
1070
查看次数