【问题标题】:Google App Engine: action on datastore changedGoogle App Engine:对数据存储区的操作已更改
【发布时间】:2014-11-21 10:41:29
【问题描述】:

我正在构建一个 GAE 支持的应用程序,它能够存储数据集。外部应用程序可以使用 Google Cloud Endpoints 访问此数据集。

当外部应用程序编辑这个数据集(PUT POST DELETE)时,我想在我的 GAE 上运行一个脚本。我可以通过将此代码添加到 PUT/POST/DELETE api 方法来做到这一点;示例:

/**
 * This inserts a new entity into App Engine datastore. If the entity already
 * exists in the datastore, an exception is thrown.
 * It uses HTTP POST method.
 *
 * @param sensor the entity to be inserted.
 * @return The inserted entity.
 */
@ApiMethod(name = "insertSensor")
public Sensor insertSensor(Sensor sensor) {
    PersistenceManager mgr = getPersistenceManager();
    try {
        if (containsSensor(sensor)) {
            throw new EntityExistsException("Object already exists");
        }
        mgr.makePersistent(sensor);
        ########RUN SCRIPT HERE########
    } finally {
        mgr.close();
    }
    return sensor;
}

但我想知道 GAE 是否针对此类问题提供更好的解决方案?

【问题讨论】:

  • 您是否正在寻找数据存储区 PrePut 和 PostPut 回调 (docs) 之类的东西?
  • 确实如此。虽然他们不提供 PostGET 以及 PrePOST 和 PostPOST 的回调?
  • 也许我误解了你的问题:这些回调用于数据存储区 putget 操作。这不是你所追求的吗?

标签: java rest google-app-engine google-cloud-datastore


【解决方案1】:

如果您希望在收到有关路由处理程序或 Endpoints API 函数的请求时执行其他处理或操作,I'd recommend strongly that you look into Task Queues 可解决该问题。这使您能够执行您定义的后台处理/挂钩,同时保持您的请求的低延迟,确保客户端拥有他们需要的数据,而不会受到您的应用程序需要进行与服务请求无关的额外处理的干扰。

【讨论】:

    猜你喜欢
    • 2012-10-08
    • 1970-01-01
    • 1970-01-01
    • 2011-02-16
    • 2013-12-03
    • 1970-01-01
    • 1970-01-01
    • 2010-12-26
    • 1970-01-01
    相关资源
    最近更新 更多