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



我正在创建一个流,该流发出twitter搜索请求,在每条推文中循环,并推送到目标连接器(文件、jdbc等)。有些属性,如user.screenName、text和id,我希望在流中的多个步骤中使用。如果没有DataWeave,我最初的反应是使用消息属性转换步骤来设置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
}

查看有关目标的DataWeave文档https://docs.mulesoft.com/mule-user-guide/v/3.7/using-dataweave-in-studio#handling-多输出

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

最新更新