将来自 REST API 的增量数据导入 SQL azure

Bringing incremental data in from REST APIs into SQL azure

我的需求如下: - 需要从第 3 方 API 获取数据到 SQL azure。

由于最后两个原因,我选择了每天触发的功能应用程序而不是可以查询网络的数据工厂APIs。

有更好的方法吗? 此外,我正在考虑将所有 JSON 推入 Blob 存储,然后将数据从 JSON 解析到 SQL Azure。有什么建议吗?

也许你可以通过SQL服务器代理创建一个定时任务。

SQL server Agent--new job--Steps--new step:

在命令中,输入您的 Import JSON documents from Azure Blob Storage sql 状态表。

Schedules--new schedule: 设置执行时间。

但我认为 Azure 函数更适合您 this.Azure Functions 是一种解决方案,可以轻松地 运行 宁小段代码,或 "functions," 在云中。您可以只编写手头问题所需的代码,而不必担心整个应用程序或 运行 它的基础架构。函数可以提高开发效率,您可以使用自己选择的开发语言,例如 C#、F#、Node.js、Java 或 PHP。

更直观高效。

希望对您有所帮助。

如果您可以在 api 中设置默认的前 N ​​个值,那么您可以使用 web activity in azure data factory to call your rest api to get the response data.Then configure the response data as input of copy activity(@activity('ActivityName').output) and the sql database as output. Please see this thread :Use output from Web Activity call as variable.

Web activity 支持访问令牌的 authentication 属性。

Also I am thinking of pushing all JSON into Blob store and then parsing data from the JSON into SQL Azure. Any recommendations?

嗯,如果您可以将数据转储到 blob 存储中,那么 azure stream analytics 是您的最佳选择。

您可以 运行 将日常工作 select 或使用 asa sql ,then dump the data into sql database.Please see this official sample.

解析 json 数据

调用所有页面需要多长时间?如果是 under ten minutes,那么我的建议是构建一个查询 API 并将 json 数据直接插入 SQL 数据库的 Azure 函数。

Azure 函数

Azure 函数非常cost effective. The first million execution are free. If it takes longer than ten, then have a look at durable functions. For handling pagination, we have plenty of examples. Your exact solution will depend on the API you are calling and the language you are using. Here is an example in . Here is one for Python using Requests. For both, the pattern is similar. Get the total number of pages from the API, set a variable to that value, and loop over the pages; Getting and saving your data in each iteration. If the API won't provide the max number of pages, then loop until you get an error. Protip: Make sure specify an upper bound for those loops. Also, if your API is flakey or has intermittent failures, consider using a graceful retry pattern such as exponential backoff

Azure SQL Json 索引计算列

您提到将数据作为 json 文件存储到存储容器中。你确定你需要那个吗?如果是这样,那么您可以 create an external table link between the storage container and the database. That has the advantage of not having the data take up any space in the database. However, if the json will fit in the database, I would highly recommend dropping that json right into the SQL database and leveraging indexed calculated columns 非常快速地查询 json。

使用这种配对应该可以提供令人难以置信的性价比!让我们知道您最终使用了什么。

扩展需要考虑的一件事是并行化查询和处理。如果没有排序要求,或者如果处理 所有 记录将花费比 10 分钟函数超时更长的时间。或者,如果您想在传输过程中处理一些 tweaking/transformation 数据,或者如果您对不同类型的数据有不同的目的地。或者如果你想避免失败——例如,你的函数在处理中途失败并且你不想重新查询 API。或者您以不同的方式获取数据并希望在流程的特定步骤开始处理(而不是从入口点开始 运行)。种种原因。

我要提醒的是,并行度与复杂性的最佳程度在很大程度上取决于您的舒适度和要求。下面的示例有点像 'extreme' 示例,它将过程分解为离散的步骤并为每个步骤使用一个函数;在某些情况下,拆分特定步骤并将它们合并为一个步骤可能没有意义。 Durable Functions 还有助于简化此流程的编排工作。

  • 一个计时器驱动的函数,它查询 API 以了解所需页面的深度,或将其他页面排队到实际进行分页 API 调用的第二个函数
  • 该函数然后查询 API,并写入临时区域(如 Blob)或将每一行放入队列中以成为 written/processed(例如,类似于存储队列,因为它们既便宜又快速,或者如果多方感兴趣,则可以使用服务总线队列(例如,pub/sub)
  • 如果写入暂存 blob,blob 触发函数读取 blob 并将单个写入排队到队列(例如,存储队列,因为存储队列对于这样的东西来说既便宜又快速)
  • 另一个队列触发函数实际上处理将各个行写入下一个系统,SQL 或其他。

您将从中获得一些并行化,以及从过程中的任何步骤开始的能力,以及格式正确的消息。如果您的处理器遇到错误数据,诸如毒药 queues/dead 字母队列之类的东西将有助于处理异常情况,因此您可以手动修复错误数据,而不是整个进程都死掉。