gpt4 book ai didi

amazon-web-services - 通过 SQS 向 Elastic Beanstalk 工作线程环境发布消息

转载 作者:行者123 更新时间:2023-12-04 11:41:50 25 4
gpt4 key购买 nike

我在弹性 beantalk 上有一个 docker 应用程序,具有 Web 服务器和工作环境。
工作环境当前通过 cron 运行预定的作业。
我正在尝试将服务器连接到工作人员以实现以下目标:

  • 客户端向服务器发送请求 (/trigger_job)
  • 服务器通过将 JSON 消息发送到 SQS 队列 (/perform_job)
  • 将作业卸载给工作程序
  • Worker 通过读取来自 SQS 的消息来执行作业

  • 我无法找到有关 JSON 消息应该是什么样子的文档。提到了一些 HTTP header in the official documentation .但是没有提到在工作环境中指定所需端点的 header 。
    # server.py
    from bottle import post, HTTPResponse


    @post('/trigger_job')
    def trigger_worker_job():
    # should send a JSON message to sqs to trigger the '/perform_job'
    # Need help with what the JSON message looks like
    return HTTPResponse(status=200, body={'Msg': 'Sent message'})
    # worker.py
    from bottle import post, HTTPResponse


    @post('/perform_job')
    def perform_job():
    # job is performed in the worker environment

    return HTTPResponse(status=200, body={'Msg': 'Success'})

    最佳答案

    在 Python 中,您可以从 Python 示例应用程序中了解这是如何实现的,您可以在此 aws doc step 4: Deploy a New Application Version 上找到该应用程序。 .

    您可以在 beanstalk 工作环境控制台中配置 SQS 端点。配置 > worker > 选择一个 worker 队列

    # for example: 
    environ['HTTP_X_AWS_SQSD_TASKNAME']
    environ['HTTP_X_AWS_SQSD_SCHEDULED_AT']
    logger.info("environ X-Aws-Sqsd-Queue %s" % environ['HTTP_X_AWS_SQSD_QUEUE'])

    # regarding your message attribute. For example, the attribute name is Email,
    # you can extract it via environ['HTTP_X_AWS_SQSD_ATTR_EMAIL']).
    # Make sure that the attribute name is all capital.
    logger.info("environ X-Aws-Sqsd-Attr Email %s" % environ['HTTP_X_AWS_SQSD_ATTR_EMAIL'])

    该消息将在图像中包含以下信息。您可以在 aws AWS Elastic Beanstalk Worker Environments 上阅读更多信息

    enter image description here

    关于amazon-web-services - 通过 SQS 向 Elastic Beanstalk 工作线程环境发布消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51864745/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com