我正在创建一个流,它发出 twitter 搜索请求,循环遍历每条推文,并推送到目标连接器(文件、jdbc 等)。我希望在流程中的多个步骤中使用一些属性,例如 user.screenName、text 和 id。如果没有 DataWeave,我最初的反应是使用消息属性转换步骤来设置 flowVars。
所以我的问题是,对于以下 Json 有效负载,DataWeave 中是否有更优雅的方式来设置 flowVar,以便我可以在整个流范围内利用该变量?还是应该继续利用消息属性转换步骤来设置 flowVars?
推特响应 JSON:
{
"sinceId": 0,
"maxId": 677174121147604994,
"refreshUrl": "?since_id=677174121147604994&q=%23MuleSoft&include_entities=1",
"count": 1,
"completedIn": 0.034,
"query": "#MuleSoft",
"tweets": [
{
"createdAt": 1450285866000,
"id": 677174121147604994,
"text": "Connectivity Benchmark Report | New opportunities in #DigitalEra #MuleSoft https://t.co/bmHKJAkTy1",
"source": "<a href=\"http://www.hootsuite.com\" rel=\"nofollow\">Hootsuite</a>",
"inReplyToStatusId": -1,
"inReplyToUserId": -1,
"inReplyToScreenName": null,
"geoLocation": null,
"place": null,
"retweetCount": 0,
"retweetedStatus": null,
"userMentionEntities": [],
"hashtagEntities": [
{
"start": 53,
"end": 64,
"text": "DigitalEra"
},
{
"start": 65,
"end": 74,
"text": "MuleSoft"
}
],
"mediaEntities": [],
"currentUserRetweetId": -1,
"user": {
"id": 228823277,
"name": "Nitor Group Ltd.",
"screenName": "nitorgroup",
"location": "Washington, DC",
"description": "Connecting the whole world of healthcare with standards-based solutions. #Direct #SecureMessaging #HealthBus #Interoperability #MovingMedicalRecords #HealthIT",
"descriptionURLEntities": [],
"profileImageUrlHttps": "https://pbs.twimg.com/profile_images/1195068249/Nitor_Logo_128x128_normal.jpg",
"url": "http://t.co/FTsfFWQcsw",
"followersCount": 364,
"status": null,
"profileBackgroundColor": "1A1B1F",
"profileTextColor": "666666",
"profileLinkColor": "F19E4F",
"profileSidebarFillColor": "333333",
"profileSidebarBorderColor": "000000",
"profileUseBackgroundImage": true,
"showAllInlineMedia": false,
"friendsCount": 1371,
"createdAt": 1292873952000,
"favouritesCount": 2,
"utcOffset": -18000,
"timeZone": "Eastern Time (US & Canada)",
"profileBackgroundImageUrl": "http://pbs.twimg.com/profile_background_images/323688620/nitor_twitter_bkgd.jpg",
"profileBackgroundImageUrlHttps": "https://pbs.twimg.com/profile_background_images/323688620/nitor_twitter_bkgd.jpg",
"profileBackgroundTiled": false,
"lang": "en",
"statusesCount": 305,
"translator": false,
"listedCount": 15,
"protected": false,
"contributorsEnabled": false,
"profileImageURL": "http://pbs.twimg.com/profile_images/1195068249/Nitor_Logo_128x128_normal.jpg",
"biggerProfileImageURL": "http://pbs.twimg.com/profile_images/1195068249/Nitor_Logo_128x128_bigger.jpg",
"miniProfileImageURL": "http://pbs.twimg.com/profile_images/1195068249/Nitor_Logo_128x128_mini.jpg",
"originalProfileImageURL": "http://pbs.twimg.com/profile_images/1195068249/Nitor_Logo_128x128.jpg",
"profileImageURLHttps": "https://pbs.twimg.com/profile_images/1195068249/Nitor_Logo_128x128_normal.jpg",
"biggerProfileImageURLHttps": "https://pbs.twimg.com/profile_images/1195068249/Nitor_Logo_128x128_bigger.jpg",
"miniProfileImageURLHttps": "https://pbs.twimg.com/profile_images/1195068249/Nitor_Logo_128x128_mini.jpg",
"originalProfileImageURLHttps": "https://pbs.twimg.com/profile_images/1195068249/Nitor_Logo_128x128.jpg",
"geoEnabled": true,
"profileBackgroundImageURL": "http://pbs.twimg.com/profile_background_images/323688620/nitor_twitter_bkgd.jpg",
"profileBannerURL": null,
"profileBannerRetinaURL": null,
"profileBannerIPadURL": null,
"profileBannerIPadRetinaURL": null,
"profileBannerMobileURL": null,
"profileBannerMobileRetinaURL": null,
"verified": false,
"followRequestSent": false,
"urlentity": {
"start": 0,
"end": 22,
"url": "http://t.co/FTsfFWQcsw",
"expandedURL": "http://nitorgroup.com",
"displayURL": "nitorgroup.com"
},
"accessLevel": 0,
"rateLimitStatus": null
},
"truncated": false,
"urlentities": [
{
"start": 75,
"end": 98,
"url": "https://t.co/bmHKJAkTy1",
"expandedURL": "http://ow.ly/VSHvk",
"displayURL": "ow.ly/VSHvk"
}
],
"favorited": false,
"retweet": false,
"retweetedByMe": false,
"possiblySensitive": false,
"contributors": [],
"accessLevel": 0,
"rateLimitStatus": null
}],
"refreshURL": "?since_id=677174121147604994&q=%23MuleSoft&include_entities=1",
"accessLevel": 2,
"rateLimitStatus": {
"remaining": 179,
"limit": 180,
"resetTimeInSeconds": 1450293371,
"secondsUntilReset": 899,
"remainingHits": 179
}
}
数据编织:
%dw 1.0
%output application/json
---
{
screenName: payload.user.screenName,
tweetId: payload.id,
tweetText: payload.text
}