标签: spring-cloud

将 Hystrix 与 Spring 数据存储库结合使用

鉴于 Spring Data 和相关 REST 存储库的主要好处之一是大多数时候开发人员不必担心底层实现,是否有一种开箱即用的方式来利用 Spring Cloud Netflix 库,特别是本例中的 Hystrix 注释,无需扩展所提供的存储库接口中的每个调用或创建我自己的实现?

spring-data spring-data-rest hystrix spring-cloud

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

弹簧云AWS。消息处理成功后手动删除SQS消息

Spring Cloud AWS (1.0.0.RC2) 中 SimpleMessageListenerContainer 类的当前实现似乎会在消息处理程序完成消息处理并且方法调用返回后自动删除消息。

在我们的应用程序中,我们需要能够处理消息并等待下游队列的异步确认,然后再从 SQS 上游队列中删除消息。就像是

接收SQS消息 -> 处理消息 -> 发布消息到RabbitMQ(线程在此完成)

删除 SQS 消息 <- 我们的应用 <- RabbitMQ 消息成功 Ack(异步)

由于消息确认通过不同的线程异步返回,因此我们需要在检查成功确认后手动从 SQS 删除消息的选项。

理想情况下,SimpleMessageListener 应可配置其运行模式(自动删除或手动删除)。

我们非常希望使用 spring aws 云库(而不是推出我们自己的)来与 SQS 集成,因为它已经负责侦听器容器 bean 生命周期管理。

请告诉我上述建议的功能是否可行,如果可行,何时可以实施和发布。

谢谢。

spring-cloud

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

如何在Spring-cloud-aws框架​​中正确实现SNS接收器?(即@NotificationMessageMapping)

我目前正在使用 STS 3.6.3SR1 和 Spring 4.1.4。尝试测试 spring-cloud-aws 在我们的应用程序中使用的可行性。

与问题相关的罐子:

spring-cloud-aws-autoconfigure-1.0.0.RC2.jar

spring-cloud-aws-context-1.0.0.RC2.jar

spring-cloud-aws-core-1.0.0.RC2.jar

spring-cloud-aws-messaging-1.0.0.RC2.jar

使用aws-sdk-1.9.3

目前我的 xml 上下文文件中有这个。

<mvc:annotation-driven>
    <mvc:argument-resolvers>
        <ref bean="notificationResolver"/>
    </mvc:argument-resolvers>
</mvc:annotation-driven> 

<aws-messaging:notification-argument-resolver id="notificationResolver" />


<aws-messaging:notification-messaging-template id="notificationMessagingTemplate" default-destination="snsChannelTopic"/> 
Run Code Online (Sandbox Code Playgroud)

目前已将此控制器类定义为我的端点。

public class AmazonSNSController {
    @Autowired
    HttpServletRequest request;

    @Autowired
    HttpServletResponse response;

    @NotificationSubscriptionMapping
    public void handleSubscriptionMessage(SnsHelper status) throws IOException {
        //We subscribe to start receive the message
        status.setRequest(request);
        status.setResponse(response);
        status.confirmSubscription();
    }

    @NotificationMessageMapping
    public void handleNotificationMessage(@NotificationSubject String subject, @NotificationMessage String message) {
        System.out.println(subject + message);
    }

    @NotificationUnsubscribeConfirmationMapping
    public void handleUnsubscribeMessage(SnsHelper status) {
        //e.g. …
Run Code Online (Sandbox Code Playgroud)

java spring amazon-web-services amazon-sns spring-cloud

5
推荐指数
0
解决办法
4406
查看次数

使用 Spring Boot 和 Netflix Zuul 的简单反向代理

我正在寻找使用 Spring Boot 实现一个简单的反向代理,即:

  • 轻松添加路线
  • 能够在每个路由的基础上添加自定义身份验证
  • 根据需要添加其他标头

我查看了注释提供的功能@EnableZuulProxy,但它似乎太重量级了,因为我不想使用 Eureka、Ribbon 或 Hystrix。然而,@EnableZuulServer配置有点轻。

有人能提供一个我所追求的例子吗?Netflix Zuul 是正确的选择吗?还是还有其他我应该考虑的库?

谢谢!

netflix spring-boot spring-cloud netflix-zuul

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

Spring Cloud Sleuth 如何在开箱即用的 Webflux 中传播 MDC 上下文,以便其内容可以记录在不同的线程中?

我想知道 Spring Cloud Sleuth 如何在线程之间传播 MDC 上下文,从而使 MDC 参数可用。

我读过这篇文章https://simonbasle.github.io/2018/02/contextual-logging-with-reactor-context-and-mdc/建议使用订阅者上下文在线程之间传播 MDC 状态。

我需要对某些请求标头中的其他参数执行类似操作,因此我创建了将其放入当前线程的 MDC 并将其存储在订阅者上下文中的操作。但是,恢复执行的下一个线程不可用。不知何故,我应该使用上下文中的值在新线程中再次调用 MDC,但是如何调用?

@Slf4j
@RequiredArgsConstructor
@Order(Ordered.HIGHEST_PRECEDENCE)
public class ReactiveRequestCorrelationFilter implements WebFilter {

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
        String principal = exchange.getRequest().getHeaders().getFirst("principal-header");
        MDC.put("principal", principal);
        return chain.filter(exchange)
                .subscriberContext(Context.of("principal", principal))
                .doOnTerminate(MDC::clear);
    }

}
Run Code Online (Sandbox Code Playgroud)

看看这个控制器映射:

    @GetMapping(value = "/v1/departments", produces = MediaType.APPLICATION_JSON_VALUE)
    public Flux<Department> getDepartments() {
        log.info("getDepartaments");
        return webClient.get().uri("http://someService:8080/api/v1/departamentosFoo").retrieve().bodyToFlux(Departments.class)
                .doOnNext(dep -> log.info("found department {}", dep));
    }
Run Code Online (Sandbox Code Playgroud)

它生成此日志:

logging.pattern.console="%magenta([%thread]) [%X{traceId}] [%X{spanId}] [%X{principal}]  - %m%n"
Run Code Online (Sandbox Code Playgroud)
[boundedElastic-2] [d0a916db8be0cbf7] [d0a916db8be0cbf7] [] …
Run Code Online (Sandbox Code Playgroud)

spring-boot project-reactor spring-cloud spring-cloud-sleuth spring-webflux

5
推荐指数
3
解决办法
4292
查看次数

Spring Cloud Gateway 中每个备用请求的 404 错误

我在 spring 云网关中遇到了一个非常奇特的问题。每个备用请求都会返回 404。这发生在我在 api-gateway 中配置的所有服务中,无一例外。我什至不知道从哪里开始调试这个问题。

这是我用于通用配置的 application.yml 文件。

server:
  port: 8080
  ssl:
    enabled: true
    key-store: classpath:keystore.p12
    key-store-password: password
    key-store-type: pkcs12
    key-alias: tomcat

security:
  require-ssl=true:
logging:
  level:
    org:
      springframework:
        cloud.gateway: DEBUG
        http.server.reactive: DEBUG
        web.reactive: DEBUG

spring:
  application:
    name: api-gateway
  cloud:
    gateway:
      httpclient:
        ssl:
          useInsecureTrustManager: true
Run Code Online (Sandbox Code Playgroud)

这是我的java配置文件


@EnableWebFluxSecurity
public class SecurityConfig {

    @Bean
    public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http,
                                                            ReactiveClientRegistrationRepository clientRegistrationRepository) {
        // Authenticate through configured OpenID Provider
        http.oauth2Login();
        // Also logout at the OpenID Connect provider
        http.logout(logout -> logout.logoutSuccessHandler(new OidcClientInitiatedServerLogoutSuccessHandler(
                clientRegistrationRepository)));
        // …
Run Code Online (Sandbox Code Playgroud)

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

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

没有发现服务器的 Spring Loadbalancer 配置

我目前正在研究有关客户端负载平衡的 POC。 

我想为此使用 Spring Cloud Loadbalancer。但与 Netflix Ribbon 不同的是,我找不到一种方法来配置 Spring Cloud Loadbalancer 以在没有 Eureka 等发现服务器的情况下工作。 

请您让我知道是否有一种方法可以将其配置为在没有发现服务器的情况下工作(只需提供 IP 地址列表)。

谢谢

spring load-balancing spring-cloud netflix-eureka netflix-ribbon

5
推荐指数
0
解决办法
1783
查看次数

如何使用 Spring Cloud Gateway 自定义过滤器来过滤每个请求?

这是我第一次使用 Spring Cloud Gateway 实现。

我需要过滤每个请求并在某些路径上应用过滤器验证。按照 Baeldung 自定义过滤器教程,我制作了一个简单的应用程序来过滤请求。

应用程序必须释放路径,/actuator/health并验证后端服务的特定路径。到目前为止,我已经实现了 aGlobalFilter和 a GatewayFilterFactory。每个请求都会调用全局过滤器,但在应用程序启动时只调用一次 GatewayFilter,这样我就无法对每个请求进行身份验证。身份验证逻辑是关于特定的头字段。所以,我的颗粒化问题是:

  1. 如何使用特定路径验证每个请求?
  2. 如何拒绝请求并发送错误消息?

全局过滤器

@Component
public class LoggingGlobalPreFilter implements GlobalFilter {

    final Logger LOGGER = LoggerFactory.getLogger(LoggingGlobalPreFilter.class);

    @Override
    public Mono<Void> filter(
            ServerWebExchange exchange,
            GatewayFilterChain chain) {
        LOGGER.info("Global Pre Filter executed");
        return chain.filter(exchange);
    }

}
Run Code Online (Sandbox Code Playgroud)

网关过滤器

@Component
public class LoggingGatewayFilterFactory extends
        AbstractGatewayFilterFactory<LoggingGatewayFilterFactory.Config> {

    final Logger LOGGER =
            LoggerFactory.getLogger(LoggingGatewayFilterFactory.class);

    public LoggingGatewayFilterFactory() {
        super(Config.class);
    }

    private Mono<Void> onError(ServerWebExchange exchange, String err, HttpStatus httpStatus)  {
        ServerHttpResponse response …
Run Code Online (Sandbox Code Playgroud)

java spring spring-cloud spring-cloud-security spring-cloud-gateway

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

微服务不从 spring-cloud-config-server 微服务中获取属性

我想用 spring 云配置服务器构建一个简单的微服务应用程序。我正在使用 Github 存储库来存储我的配置文件。目前,我有两个非常简单的微服务。其中之一是云配置服务器,它从 Github 上的远程存储库中检索属性。在这个微服务的主类中,我添加了 @EnableConfigServer 注释,并在 application.properties 文件中提供了几个属性:

spring.application.name=cloud-config-server
server.port=8888

spring.cloud.config.server.git.uri=*Remote repo URI*
spring.cloud.config.server.git.username=*Username*
spring.cloud.config.server.git.password=*Password*
spring.cloud.config.server.git.clone-on-start=true
Run Code Online (Sandbox Code Playgroud)

如果我去 http://localhost:8888/cloud-config-server/default 一切正常,我的 spring 云配置服务器成功检索属性。

在我的第二个微服务中,我添加了带有 2 个属性的 bootstrap.properties 以连接到 cloud-config-server:

spring.cloud.config.uri=http://localhost:8888
spring.cloud.config.name=cloud-config-server
Run Code Online (Sandbox Code Playgroud)

而且我还添加了这个依赖项

       <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
       </dependency>
Run Code Online (Sandbox Code Playgroud)

不幸的是,我的微服务不会从 cloud-config-server 检索属性。当我尝试通过 @Value 注释使用属性时,出现错误:

自动装配依赖项的注入失败;嵌套异常是 java.lang.IllegalArgumentException:无法解析值“${test.text}”中的占位符“test.text”

我敢肯定,我的属性名称“test.text”没有打错。

java spring spring-boot spring-cloud spring-cloud-config

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

Spring Cloud 负载均衡器和 Ribbon 有什么区别?

我们的团队正计划从

  1. Spring Cloud Netflix Ribbon 到 Spring Cloud LoadBalancer 并使用 spring-cloud-kubernetes 作为发现客户端。
  2. 使用 Spring Cloud Gateway 代替 Zuul
  3. 和 Resilience4j 而不是 Hystrix。

需要进行哪些必要的更改,我们是否需要更改等效的属性。你能帮我们从哪里开始吗?

java spring-cloud spring-cloud-kubernetes

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