简体   繁体   English

Spring 云总线与 AWS Kinesis stream @refreshscope

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

I read everywhere @RefreshScope for cloud bus applications work with RabbitMQ and Kafka.我到处阅读@RefreshScope,了解云总线应用程序与 RabbitMQ 和 Kafka 一起使用。 But in my case, I am using AWS Parameter store.但就我而言,我使用的是 AWS Parameter store。 I want all my client instances to be refreshed automatically without rebuilding servers on AWS Console.我希望自动刷新所有客户端实例,而无需在 AWS 控制台上重建服务器。

I created AWS Eventbridge from Paramstore to notify Kinesis Stream but I am not able to figure out how can it notify all my client nodes instead of load balancer refresh to only one node(instance).我从 Paramstore 创建了 AWS Eventbridge 以通知 Kinesis Stream 但我无法弄清楚它如何通知我的所有客户端节点而不是负载均衡器仅刷新到一个节点(实例)。

Thank you for responding in advance.感谢您提前回复。

I've never worked with AWS Eventbridge / Kinesis, however:但是,我从未使用过 AWS Eventbridge / Kinesis:

@RefreshScope is something that belongs to spring cloud and not not AWS. @RefreshScope属于 spring 云而不是 AWS。

More precisely, beans defined with this scope will be re-loaded by spring without reloading the whole application context "dynamically" when configuration changes in spring boot cloud configuration service.更准确地说,当 spring 引导云配置服务中的配置更改时,使用此 scope 定义的 bean 将由 spring 重新加载,而无需“动态”重新加载整个应用程序上下文。 Usually this means that you don't have to restart the application.通常这意味着您不必重新启动应用程序。

Now, spring boot microservice should be deployed with actuator that exposes refresh endpoint.现在,spring 引导微服务应该与公开refresh端点的执行器一起部署。 Calling this endpoint manually will cause all the @RefreshScope beans to reload.手动调用此端点将导致所有@RefreshScope bean 重新加载。

Here is the source code of the RefreshEndpoint :这是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;
    }

}

As you see, its merely invokes contextRefresher.refresh() , ContextRefresher is a bean that you can inject in your custom code that will listen to the changes coming from AWS Parameter store (it should somehow invoke it directly or maybe send some message that you could consume or something).如您所见,它仅调用contextRefresher.refresh()ContextRefresher是一个 bean,您可以将其注入您的自定义代码中,该代码将侦听来自 AWS Parameter store 的更改(它应该以某种方式直接调用它,或者发送一些消息告诉您可以消费什么的)。

If you're using spring-cloud-bus (disclaimer, I've never worked with it) it exposes the bus-refresh endpoint as well (pretty similar mechanism to what I've described), read spring-cloud-bus documentation for more details.如果您使用的是 spring-cloud-bus (免责声明,我从未使用过它)它也会公开bus-refresh端点(与我所描述的机制非常相似),请阅读spring-cloud-bus 文档更多细节。

Thank you Team for sharing info.感谢团队分享信息。

Here is what I did to make it work.这是我为使其工作所做的工作。 Added these two libraries to my project将这两个库添加到我的项目中

    <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>

And added these two entries into bootstrap.properties并将这两个条目添加到 bootstrap.properties

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

And refreshing using this endpoint (/bus-refresh)并使用此端点刷新 (/bus-refresh)

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

相关问题 无法使用spring cloud kinesis stream启动spring boot - Unable to start spring boot with spring cloud kinesis stream 如何在 spring-cloud-stream-binder-kinesis 中使用 STSAssumeRoleSessionCredentialsProvider 进行配置 - How to Configure using STSAssumeRoleSessionCredentialsProvider in spring-cloud-stream-binder-kinesis Spring 未应用 @RefreshScope 的云配置客户端 - Spring Cloud Config Client with @RefreshScope not applying Spring Cloud RefreshScope后刷新挂钩 - Spring Cloud RefreshScope post-refresh hooks Spring 云应用程序无法连接到 AWS Kinesis 'dynamoDBClient' 不得为 null - Spring Cloud application fails to connect to AWS Kinesis 'dynamoDBClient' must not be null 在Spring Cloud中使用@RefreshScope重新加载Spring属性时出错 - error while reloading spring properties with @RefreshScope in spring cloud Spring Cloud Config Server并在整个Spring Boot应用程序上应用@RefreshScope - Spring Cloud Config Server and applying @RefreshScope on an entire Spring Boot application 如何在 spring boot + cloud 中禁用 refreshScope 运行状况指示器? - How can I disable the refreshScope health indicator in spring boot + cloud? 没有Spring Cloud Config Server的RefreshScope运行时配置 - RefreshScope Runtime Configuration Without Spring Cloud Config Server 弹簧启动和弹簧集成aws运动学错误 - spring boot and spring integration aws kinesis error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM