简体   繁体   English

如何从在自动缩放组后面运行并连接到 jms 队列的 aws ecs docker 容器中排出消息

[英]How to drain message from aws ecs docker container which is running behind autoscaling group and connected to jms queue

we are using aws ecs task to run our docker containers.我们正在使用 aws ecs 任务来运行我们的 docker 容器。 our applications are connecting to TIBCO queues and using AlpakkaJMSListeners to read messages from queues.我们的应用程序正在连接到 TIBCO 队列并使用 AlpakkaJMSListeners 从队列中读取消息。

We want to enable autoscaling for these containers at ec2 instance level.我们希望在 ec2 实例级别为这些容器启用自动缩放。 We have application LB with Target Group defined for some of our services which have http end points.我们为我们的一些服务定义了目标组的应用程序 LB,这些服务具有 http 个端点。

I know that if we use Target Group with http health check enabled and autoscaling on instances then ecs task will drain requests before stopping container.我知道如果我们使用启用了 http 健康检查并在实例上自动缩放的目标组,那么 ecs 任务将在停止容器之前耗尽请求。

Question is how to achieve the same behavior (ie draining all messages before container is stopped) when our containers are connected to JMS Queues with autoscaling?问题是当我们的容器连接到具有自动缩放功能的 JMS 队列时,如何实现相同的行为(即在容器停止之前耗尽所有消息)?

we found a workaround for this one, by default ECS task when triggers TERM signal it waits for 30 sec to let current thread finish their task.我们找到了解决这个问题的方法,默认情况下,ECS 任务在触发 TERM 信号时等待 30 秒,让当前线程完成任务。

ref - https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_StopTask.html ,参考 - https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_StopTask.html
By adding a SIGTERM handler in the listener we can stop consumption of msgs and process inflight messages.通过在侦听器中添加 SIGTERM 处理程序,我们可以停止使用消息并处理飞行中的消息。

add Terminal signal handling in jms listener like below在 jms 侦听器中添加终端信号处理,如下所示

Signal.handle(new Signal("TERM"), signal -> {
        log.info("Received termination signal" +signal.getName());
        if ("TERM".equals(signal.getName())) {
            try {
                stopStream();
                log.info("Stopped stream");
            } catch (Exception e) {
                log.error("Exception while handling signal: "+e);
            }
        }
    });

note: in order to receive signal make sure your application is running as a separate java process;注意:为了接收信号,请确保您的应用程序作为单独的 java 进程运行;

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

相关问题 Terraform中的ECS服务如何连接到AWS自动缩放组 - How is an ECS service in Terraform connected to an AWS autoscaling group 如何为在 AWS ECS 中运行的 Docker 容器配置“ulimits”? - How do I configure "ulimits" for a Docker container running in AWS ECS? 在 AWS ECS 容器中运行节点应用程序的问题 - Issue with running Node application in AWS ECS container 使用 AWS ECS 从运行在 Linux 容器上的 .NET 核心应用程序访问具有集成安全性的 SQL 服务器 - Access SQL Server with Integrated security from .NET Core app running on Linux container using AWS ECS 为 AWS 自动缩放组配置 SSL - Configuring SSL for an AWS autoscaling group 如何使用 ansible 显示 AWS 自动缩放组名称? - How to display AWS autoscaling group name using ansible? 我们可以在 AWS ECS docker 容器上挂载 EFS 吗? - Can we mount EFS on AWS ECS docker container? Angular 2 应用程序部署在 AWS 上运行的 docker 容器中 - Angular 2 app deploy in a docker Container running on AWS 如何使用 intelliJ 中的 AWS 工具包将文件复制到运行 Lambda 的 docker 容器 - How to copy file to docker container running Lambda with AWS Toolkit in intelliJ AWS websocket 容器 cdk ecs - AWS websocket container cdk ecs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM