LoginSignup
2
2

More than 5 years have passed since last update.

NiFiで、REST APIからのデータ取得

Posted at

ゴール

指定のREST API Endpointから情報を定期的に取得する。
ゴール1:取得した情報をマージして、HDFS(あるいはローカルファイル、S3)に保存する
ゴール2:取得したAPIのレスポンスJSONの特定PATHの値を取得する

全体図

image.png

手順

REST API コール

InvokeHTTPプロセッサー利用

ScheduleタブのRun schedule値を0 secから 30 secに変更
image.png

Endpointなどの値を設定:
image.png

値マージ:MergeContentプロセッサー利用

image.png

ローカルファイルに保存:PutFileプロセッサー

image.png

JSONの特定PATHの値を取得し、組み立て直す

値取得:EvaluateJsonPathプロセッサー利用

image.png
* PropertiesタブのDestination値を flowfile-attribute に変更
* プラスアイコンをクリックし、新しいProperty-Valueを追加。
* Propertyは自分で定義し、ValueはJSONのパス

ヤフー 天気情報のREST APIアカウント取得

API実行結果

{
  "ResultInfo": {
    "Count": 1,
    "Total": 1,
    "Start": 1,
    "Status": 200,
    "Latency": 0.003801,
    "Description": "",
    "Copyright": "(C) Yahoo Japan Corporation."
  },
  "Feature": [
    {
      "Id": "201810082015_139.73229_35.663613",
      "Name": "地点(139.73229,35.663613)の2018年10月08日 20時15分から60分間の天気情報",
      "Geometry": {
        "Type": "point",
        "Coordinates": "139.73229,35.663613"
      },
      "Property": {
        "WeatherAreaCode": 4410,
        "WeatherList": {
          "Weather": [
            {
              "Type": "observation",
              "Date": "201810082015",
              "Rainfall": 0.00
            },
            {
              "Type": "forecast",
              "Date": "201810082025",
              "Rainfall": 0.00
            },
            {
              "Type": "forecast",
              "Date": "201810082035",
              "Rainfall": 0.00
            },
            {
              "Type": "forecast",
              "Date": "201810082045",
              "Rainfall": 0.00
            },
            {
              "Type": "forecast",
              "Date": "201810082055",
              "Rainfall": 0.00
            },
            {
              "Type": "forecast",
              "Date": "201810082105",
              "Rainfall": 0.00
            },
            {
              "Type": "forecast",
              "Date": "201810082115",
              "Rainfall": 0.00
            }
          ]
        }
      }
    }
  ]
}

特定パスの値取得し、確認する

LogAttributeで値を随時確認出来る

文字列の変更

image.png
ReplaceTextプロセッサー:
Replacement Valueの値を変更。

provenanceで値を確認

image.png
LogAttributeプロセッサーに右クリックし、メニューにあるView data provenanceを選ぶ。

data provenanceページが表示される:
image.png
表示したいデータを選ぶ:

ContentタブのViewボタンを押す:
image.png

image.png

2
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2