Laravel 多个服务器使用 AWS 队列
Laravel multiple servers working with AWS queue
我在两台服务器(使用负载均衡器)中有 laravel 应用程序 运行,我想知道如果我将作业放入 AWS SQS 队列并且两台服务器都订阅了会发生什么队列。
- 是否有可能多次处理该作业?
- 是否有任何设置方式,以便将作业放入队列的同一台服务器处理该作业(想想文件首先存储在磁盘中的文件上传)。
感谢任何 experience/tips/advice 具有这种设置的人。
Is there any way to setup things so the same server that put the job
in the queue handles the job (think file uploads where the file is
stored in disk first).
只需将每台服务器配置为使用自己的 SQS 队列,而不是共享同一个队列。这样你就 100% 知道推送作业的服务器就是处理它的服务器。
您可以通过每个服务器上的 .env
配置文件执行此操作。
Is there any chance that the job will be processed more than once?
是的,SQS 只保证至少一次交货。您应该构建您的应用程序以允许传递消息的多个副本。 http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/standard-queues.html#standard-queues-at-least-once-delivery
通常解决这个问题的方法是拥有一个可以锁定消息的唯一标识符的服务。这样就可以限制临界区了。
Is there any way to setup things so the same server that put the job in the queue handles the job (think file uploads where the file is stored in disk first).
正如 Laurence 所建议的,您可以为每个实例设置单独的队列。
我在两台服务器(使用负载均衡器)中有 laravel 应用程序 运行,我想知道如果我将作业放入 AWS SQS 队列并且两台服务器都订阅了会发生什么队列。
- 是否有可能多次处理该作业?
- 是否有任何设置方式,以便将作业放入队列的同一台服务器处理该作业(想想文件首先存储在磁盘中的文件上传)。
感谢任何 experience/tips/advice 具有这种设置的人。
Is there any way to setup things so the same server that put the job in the queue handles the job (think file uploads where the file is stored in disk first).
只需将每台服务器配置为使用自己的 SQS 队列,而不是共享同一个队列。这样你就 100% 知道推送作业的服务器就是处理它的服务器。
您可以通过每个服务器上的 .env
配置文件执行此操作。
Is there any chance that the job will be processed more than once?
是的,SQS 只保证至少一次交货。您应该构建您的应用程序以允许传递消息的多个副本。 http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/standard-queues.html#standard-queues-at-least-once-delivery
通常解决这个问题的方法是拥有一个可以锁定消息的唯一标识符的服务。这样就可以限制临界区了。
Is there any way to setup things so the same server that put the job in the queue handles the job (think file uploads where the file is stored in disk first).
正如 Laurence 所建议的,您可以为每个实例设置单独的队列。