使用 ENS

我们提供此使用案例以帮助您理解使用“事件通知 Web 服务”的方法。尽管可能有使用“事件通知 Web 服务”的其他方法,此使用案例代表最为常见的使用案例和我们推荐的方法。

1. 您的应用程序第一次启动时,您尚未检索任何事件且您没有已存储的分页 Cookie。要检索您的首个事件“页面”,请调用“获取事件”操作,并结合您要的“事件类型”以及符合您需要的“起始日期”和“数量限制”组合。例如,您可仅使用“起始日期”参数检索特定日期以来的所有事件,或者使用“数量限制”参数检索特定数量的最近事件。或者您可以将二者结合,检索特定日期之后特定数量限制的事件。您还可以提供“每页事件数”参数,以指定每次调用该服务时您想要检索的事件数量,或者您可以直接略过该参数,以允许“事件通知 Web 服务 (ENS)”自行决定向您发送的事件数。

2. ENS 将针对您指定的“事件类型”回复一组“事件通知”。由于您需要使用分页 Cookie 从您离开位置重新开始并检索额外事件,当您处理完那些事件后,请在安全位置保存分页 Cookie。如果您使用数据库存储事件数据,最好的方法是在数据库事务内处理并存储所有事件,然后也在提交事务之前,将分页 Cookie 存储在同一事务上下文中。这样,如果您的应用程序在处理一组事件时失败,则它能自动返回至您之前的分页 Cookie 并且不会有丢失或遗漏事件的风险。

  1. 如果“存在更多页面”标记被设置为“是”,则表示有更多有待检索的新事件。在这种情况下,您可能想要立刻调用“获取更多”以检索更多事件。注意:您仍必须等待分页 Cookie 中“退避时间”所指定的时间过去,否则您的调用将被拒绝而您仍需等待。

  2. 如果“存在更多页面”标记被设置为“否”,则表示没有更多有待检索的新事件。在这种情况下,您需要等待一段时间直至新事件出现。时间的长短由您决定,但需要注意的是:您必须至少等待“退避时间”所规定的时间过去,才能再次使用分页 Cookie。

3. 当您可以调用“获取更多”时,请使用之前调用“获取事件”或“获取更多”时返回的分页 Cookie。为方便起见,您不需要保留“使用期限”和“退避时间”字段,但“分页 Cookie”字段必须在没有被篡改的情况下传回到“获取更多”。与“获取事件”一样,“获取更多”也允许您为“每页事件数”指定一个值来限制每次调用中接收到的事件数量。

4. 返回步骤 2,处理“获取更多”返回的事件。只要您喜欢,可以重复对每个新分页 Cookie 调用“获取更多”并处理检索到的事件这个过程,您将不断地获取进入系统的新事件。


亚马逊官网原文详情:   

Use Case for Event Notification Web Service


This use case can help you understand how to use the Event Notification Web Service (ENS). Although there may be other ways to use the ENS, this represents the most common use case and the method we recommend.


  1. The first time your application starts, you will have retrieved no events and you will not have a stored PagingCookie. To retrieve your first "page" of events, call GetEvents with the EventType you want and a combination of StartDate and Limit that fits your needs.

    For example, you can use just the StartDate parameter to retrieve all the events since a particular date, or the Limit parameter to retrieve just a certain number of your latest events. Or you can combine the two to limit the number of events retrieved after a certain date. You can also provide the EventsPerPage parameter to specify how many events you would like to retrieve in each call to the service, or you can leave it out to allow ENS to decide how many events to send you.

  2. ENS will respond with a set of EventNotifications for the EventType you specified. After you are done processing those events, store the PagingCookie somewhere safe, since you will need it to pick up where you left off and retrieve additional events. If you are using a database to store event data, the best way to do this is to process and store all the events inside a database transaction, and then also store the PagingCookie in the same transaction context before committing the transaction. That way, if your application fails while processing a set of events, it can automatically roll back to your previous PagingCookie and there is no risk of losing or missing events.

    • If the MorePagesExist flag was set to "true," that means there are more new events waiting to be retrieved. In this case, you will probably want to call GetMore soon to retrieve more events.

      Note: You must still wait until any specified BackOffTime in the PagingCookie has passed, otherwise your call will be rejected and you will have to wait.

    • If the MorePagesExist flag was set to "false," that means there are no more new events to be retrieved. In this case, you will want to wait for some period of time for new events to come in. That amount of time is up to you, but note that you must wait at least the amount of time specified in BackOffTime before using the PagingCookie again.

  3. When you are ready to call GetMore, use the PagingCookie returned by your previous call to GetEvents or GetMore. For convenience, it is not necessary to preserve the TimeToLive and BackOffTime fields, but the PagingCookie field must be passed back to GetMore without being tampered with. Like GetEvents, GetMore also allows you to specify a value for EventsPerPage to limit the number of events you receive in each call.

  4. Return to step 2 and process the events returned by GetMore. You can repeat this process of calling GetMore with each new PagingCookie and processing events retrieved as long as you like, and you will continuously retrieve new events as they come into the system.


文章来源:亚马逊官方网站

(本文内容根据网络资料整理,出于传递更多信息之目的,不代表连连国际赞同其观点和立场)