骡子:是否可以使用DataWeave来设置flowVars

时间:2015-12-16 19:37:13

标签: mule dataweave

我正在创建一个发布Twitter搜索请求的流程,循环遍历每条推文,并推送到目标连接器(文件,jdbc等)。我想在流程中的多个步骤中使用user.screenName,text和id等属性。没有DataWeave,我最初的反应是使用Message Properties转换步骤来设置flowVars。

所以我的问题是,对于以下Json有效负载,DataWeave中是否有更优雅的方法来设置flowVar,以便我可以在整个流程范围内利用变量?或者我应该继续利用消息属性转换步骤来设置flowVars吗?

Twitter响应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
  }
}

DataWeave:

%dw 1.0
%output application/json
---
{
    screenName: payload.user.screenName,
    tweetId: payload.id,
    tweetText: payload.text
}

2 个答案:

答案 0 :(得分:2)

答案 1 :(得分:0)

简单的答案是肯定的。您可以使用<dw:set-variable ../>标记设置变量。