基于SQS消息触发SWF工作流 [英] Triggering a SWF Workflow based on SQS messages

查看:190
本文介绍了基于SQS消息触发SWF工作流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

序言:我正在尝试就一个我认为是非常常见的用例提出一个建议,并且我想使用Amazon的SWF和SQS来实现我的目标。可能还有其他服务可以更好地满足我的需求,因此,如果您有建议,请随时将它们排除。

Preamble: I'm trying to put together a proposal for what I assume to be a very common use-case, and I'd like to use Amazon's SWF and SQS to accomplish my goals. There may be other services that will better match what I'm trying to do, so if you have suggestions please feel free to throw them out.

问题: 最基本的需求是客户端(移动设备,Web服务器等)发布一条消息,该消息将在不响应客户端的情况下进行异步处理-非常基本。

Problem: The need at its most basic is for a client (mobile device, web server, etc.) to post a message that will be processed asynchronously without a response to the client - very basic.

预期的实现是使客户端将消息发布到预定的SQS队列。至此,客户端已完成。我们还将有一个已定义的SWF工作流程,负责将消息从队列中取出并(在进行一些操作之后)将其放置在Dynamo DB中-再次,所有操作都非常简单。

The intended implementation is to for the client to post a message to a pre-determined SQS queue. At that point, the client is done. We would also have a defined SWF workflow responsible for picking up the message off the queue and (after some manipulation) placing it in a Dynamo DB - again, all fairly straightforward.

我似乎无法弄清楚的是如何触发工作流程启动。从我一直在阅读的内容来看,工作流程并不是一个无限的过程。它有一个起点,一个中间和一个终点。根据SWF文档,工作流只能运行一年(在SWF中设置超时值)。

What I can't seem to figure out though, is how to trigger the workflow to start. From what I've been reading a workflow isn't meant to be an indefinite process. It has a start, a middle, and an end. According to the SWF documentation, a workflow can run for no longer than a year (Setting Timeout Values in SWF).

因此,我的问题是:如果我假设工作流代表一条消息,处理流程,每当消息发布到SQS时如何启动工作流程?

So, my question is: If I assume that a workflow represents one message-processing flow, how can I start the workflow whenever a message is posted to the SQS?

注意: SQS也是如此。这将允许我运行可以订阅SNS的服务器,然后在发布通知时启动工作流程。那当然是一种解决方案,但我想避免为单个Web服务设置服务器,然后我将不得不根据正在处理的消息数来管理/扩展。首先要考虑使用SQS / SWF的原因是拥有一个我不必担心的自动缩放系统。

Caveat: I've looked into using SNS instead of SQS as well. This would allow me to run a server that could subscribe to SNS, and then start the workflow whenever a notification is posted. That is certainly one solution, but I'd like to avoid setting up a server for a single web service which I would then have to manage / scale according to the number of messages being processed. The reason I'm looking into using SQS/SWF in the first place is to have an auto-scaling system that I don't have to worry about.

谢谢

推荐答案

我将创建一个侦听SQS队列的工作进程。收到消息后,它将调用SWF API以开始执行工作流程。应基于消息内容生成工作流执行ID,以确保重复的消息不会导致重复的工作流。

I would create a worker process that listens to the SQS queue. Upon receiving a message it calls into SWF API to start a workflow execution. The workflow execution id should be generated based on the message content to ensure that duplicated messages do not result in duplicated workflows.

这篇关于基于SQS消息触发SWF工作流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆