惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Tenable Blog
Last Week in AI
Last Week in AI
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
H
Help Net Security
F
Fortinet All Blogs
MyScale Blog
MyScale Blog
宝玉的分享
宝玉的分享
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 司徒正美
量子位
N
Netflix TechBlog - Medium
Apple Machine Learning Research
Apple Machine Learning Research
小众软件
小众软件
Recorded Future
Recorded Future
博客园 - 三生石上(FineUI控件)
Vercel News
Vercel News
aimingoo的专栏
aimingoo的专栏
I
InfoQ
Microsoft Security Blog
Microsoft Security Blog
Scott Helme
Scott Helme
The Last Watchdog
The Last Watchdog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
IT之家
IT之家
AI
AI
WordPress大学
WordPress大学
Security Archives - TechRepublic
Security Archives - TechRepublic
Google Online Security Blog
Google Online Security Blog
U
Unit 42
V2EX - 技术
V2EX - 技术
MongoDB | Blog
MongoDB | Blog
Schneier on Security
Schneier on Security
博客园 - Franky
H
Heimdal Security Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Jina AI
Jina AI
W
WeLiveSecurity
P
Privacy & Cybersecurity Law Blog
Cloudbric
Cloudbric
B
Blog RSS Feed
N
News | PayPal Newsroom
S
Securelist
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
I
Intezer
Hacker News - Newest:
Hacker News - Newest: "LLM"
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
博客园_首页
罗磊的独立博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More
雷峰网
雷峰网

博客园 - vikingwei

<<人纪>>针灸篇倪海厦 NIFI免密调用API HTTPS PostgreSQL源码安装 Installation from Source Code netstat 查看端口(sqlserver) SQL Server 常用的83条SQL语句,速速收藏 用户中心 - 博客园 用户中心 - 博客园 用户中心 - 博客园 用户中心 - 博客园 用户中心 - 博客园 用户中心 - 博客园 用户中心 - 博客园 用户中心 - 博客园 用户中心 - 博客园 用户中心 - 博客园 用户中心 - 博客园 用户中心 - 博客园 用户中心 - 博客园 用户中心 - 博客园
NIFI调用API HTTP
vikingwei · 2025-06-16 · via 博客园 - vikingwei

1.新增处理器processor: GenerateFlowFile并增加参数属性

GenerateFlowFile-->properties-->点右上角的+号Add Property-->输入要传入的参数

本例参数为:account and password.

被请求服务器端给出帐号与密码,主要是目的是获取Token,再用Token取查询获取具体的数据。

2.参数属性转换为JSON:AttributesToJSON

 AttributesToJSON-->properties-->Attributes List参数属性输入此处:account,password,此处理器将参数属性转为JSON

-->Destination转换好的json输出为文件内容:flowfile-content。

3.获取Token调用API:InvokeHTTP

InvokeHTTP-->properties-->HTTP Method根据实际选调用方法get或post-->HTTP URL设置调用的URL

-->Request Content-Type:application/json设置请求内容类型。

Request Body参数请求体通过上面的json文件传入。

{

  "account": "AccessAPIForRedcred",

  "password": "VWxNcC85ek5PUDhDS3JqODA3bWJ5UEIxd3FLMTFjc2ZEbTEwbXZ6eTh6RFBVcG5VSWhkNEowT1hxU2wwSUtoSjFYTGxlOGR6RncwUkV2ZGloQ1BURkE9PQ=="

}

Response 内容如下:

{
"status": 200,
"success": true,
"msg": "Success",
"msgDev": null,
"response": {
"success": true,
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJJRCI6IjM2MDgyIiwiVVNFUl9BQ0NPVU5UIjoiQWNjZXNzQVBJRm9yUmVkY3JlZCIsIlNUQUZGX05VTUJFUiI6IkFQSTAwMDciLCJTVEFGRl9OQU1FIjoiQWNjZXNzQVBJRm9yUmVkY3JlZCIsIk9SR19JRCI6Ijg4MCIsIk9SR19OQU1FIjoiU2hhcmVkIiwiREVQQVJUTUVOVF9DT0RFIjoiODE2OCIsIlRJVExFIjoiIiwiRU1BSUwiOiIiLCJBQ0NPVU5UX0RPTUFJTiI6Ik5PTkUiLCJDTElFTlRfVFlQRSI6IldFQiIsImp0aSI6IjRmMjRjMTRkLTIxNGMtNGM0My1iZTY0LTljYTgyMzcxNDZiZiIsImlhdCI6IjYvMTYvMjAyNSA0OjIxOjI0IFBNIiwiaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS93cy8yMDA4LzA2L2lkZW50aXR5L2NsYWltcy9leHBpcmF0aW9uIjoiNi8xNi8yMDI1IDg6MjE6MjQgUE0iLCJuYmYiOjE3NTAwNjIwODQsImV4cCI6MTc1MDA3NjQ4NCwiaXNzIjoiZUZhY3RvcnkuU2VydmljZSIsImF1ZCI6IndyIn0.FNZA9QJY5-DtUAM-wqAoBU0Y5XRVpzeyHexcywo1K-w",
"expires_in": 1440.0,
"token_type": "Bearer",
"refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE3NTAwNjIwODQsImV4cCI6MTc1MDE0ODQ4NCwiaXNzIjoiZUZhY3RvcnkuU2VydmljZSIsImF1ZCI6IndyIn0.63gdKr4AAGncrMrAGPukih5q-SyhOJ0nr8vLFUNB9rs"
}
}

4.解析JSON获取Token:EvaluateJsonPath

EvaluateJsonPath-->properties-->Destination设置输出为属性:flowfile-attribute

-->点右上角的+号Add Property-->Property:输入属性变量token(自己定义),value:$.response.token

 5.设置实际请求参数:UpdateAttribute

UpdateAttribute-->properties-->点右上角的+号Add Property-->输入要传入的参数属性:Property:START_TIME,Value:2023-12-01 00:00:00

Property:END_TIME,Value:2023-12-15 23:59:59

Property:Bearer_Token,Value:Bearer ${token}

6.实际请求参数属性转换为JSON:AttributesToJSON

 AttributesToJSON-->properties-->Attributes List参数属性输入此处:START_TIME,END_TIME,此处理器将参数属性转为JSON

-->Destination转换好的json输出为文件内容:flowfile-content。

7.获取数据调用API:InvokeHTTP

InvokeHTTP-->properties-->HTTP Method根据实际选调用方法get或post-->HTTP URL设置调用的URL

-->Request Content-Type:application/json设置请求内容类型。

Request Body参数请求体通过上面的json文件传入。

{

  "START_TIME": "2023-12-01 00:00:00",

  "END_TIME": "2023-12-15 23:59:59"

}

8.解析JSON获取数据:EvaluateJsonPath

EvaluateJsonPath-->properties-->Destination设置输出为JSON内容:flowfile-content

-->点右上角的+号Add Property-->Property:输入属性变量JSON(自己定义), value:$.response

9.JSON内容写入数据库:PutDatabaseRecord

9.1.PutDatabaseRecord-->properties-->Property:Record Reader,Value:JsonTreeReader-Global(自己在Controller Service Details定义)

JsonTreeReader-Global:Configuration-->Controller Services-->右上角点+-->选JsonTreeReader-->名称输入:JsonTreeReader-Global-->PROPERTIES-->Schema Access Strategy:Infer Schema,Starting Field Strategy:Root Node,其它属性值留空白。

9.2.PutDatabaseRecord-->properties-->Property:Statement Type,Values:INSERT

Property:Statement Type,Values:INSERT

Property:Database Connection Pooling Service,Values:数据库连接池自己选要写入的数据库即可。

Property:Schema Name,Values:imptemp

Property:Table Name,Values:要写入的表名

Property:Quote Column Identifiers,Values:true 字段名称是否加引号?

Property:Quote Table Identifiers,Values:true 表名称是否加引号。

注:table的column名称与顺序一定要与JSON中是一样的,包括数据类型。

小结:将JSON批量写入数据库,用PutDatabaseRecord比较快。