繁体   English   中英

Spring 云总线与 AWS Kinesis stream @refreshscope

[英]Spring cloud bus with AWS Kinesis stream @refreshscope

我到处阅读@RefreshScope,了解云总线应用程序与 RabbitMQ 和 Kafka 一起使用。 但就我而言,我使用的是 AWS Parameter store。 我希望自动刷新所有客户端实例,而无需在 AWS 控制台上重建服务器。

我从 Paramstore 创建了 AWS Eventbridge 以通知 Kinesis Stream 但我无法弄清楚它如何通知我的所有客户端节点而不是负载均衡器仅刷新到一个节点(实例)。

感谢您提前回复。

但是,我从未使用过 AWS Eventbridge / Kinesis:

@RefreshScope属于 spring 云而不是 AWS。

更准确地说,当 spring 引导云配置服务中的配置更改时,使用此 scope 定义的 bean 将由 spring 重新加载,而无需“动态”重新加载整个应用程序上下文。 通常这意味着您不必重新启动应用程序。

现在,spring 引导微服务应该与公开refresh端点的执行器一起部署。 手动调用此端点将导致所有@RefreshScope bean 重新加载。

这是RefreshEndpoint源代码


@Endpoint(id = "refresh")
public class RefreshEndpoint {

    private ContextRefresher contextRefresher;

    public RefreshEndpoint(ContextRefresher contextRefresher) {
        this.contextRefresher = contextRefresher;
    }

    @WriteOperation
    public Collection<String> refresh() {
        Set<String> keys = this.contextRefresher.refresh();
        return keys;
    }

}

如您所见,它仅调用contextRefresher.refresh()ContextRefresher是一个 bean,您可以将其注入您的自定义代码中,该代码将侦听来自 AWS Parameter store 的更改(它应该以某种方式直接调用它,或者发送一些消息告诉您可以消费什么的)。

如果您使用的是 spring-cloud-bus (免责声明,我从未使用过它)它也会公开bus-refresh端点(与我所描述的机制非常相似),请阅读spring-cloud-bus 文档更多细节。

感谢团队分享信息。

这是我为使其工作所做的工作。 将这两个库添加到我的项目中

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-stream-binder-kinesis</artifactId>
        <version>1.1.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-bus</artifactId>
    </dependency>

并将这两个条目添加到 bootstrap.properties

cloud.aws.region.static=us-east-1
cloud.aws.stack.auto = false

并使用此端点刷新 (/bus-refresh)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM