2

我想知道如何使用 Windows Azure Node.js SDK 获取延续令牌?例如,我现在使用 SDK 从表中检索数据:

var tableService = azure.createTableService();

tableService.getTable('UsersUserFacebookActions', function (error) {
    if (error === null) {
        var query = azure.TableQuery
            .select()
            .from('UsersUserFacebookActions')
            .where('PartitionKey eq ?', userID)
            .and('Kind eq ?', 'User')
            .and('Deleted eq ?', 'false');

        tableService.queryEntities(query, function (error, userEntities) {
            if (error === null && userEntities.length > 0) {
                // check to see if access token needs extending
                extendAccessToken(userEntities[0], function (user) {
                    callback({
                        PartitionKey: user.PartitionKey,
                        RowKey: user.RowKey,
                        Kind: user.Kind,
                        EmailAddress: user.EmailAddress,
                        AccessToken: user.AccessToken,
                        TokenExpiration: user.TokenExpiration,
                        JoinDate: user.JoinDate,
                        ChannelCount: user.ChannelCount,
                        FollowCount: user.FollowCount,
                        ChannelCountString: accounting.formatNumber(user.ChannelCount),
                        FollowCountString: accounting.formatNumber(user.FollowCount),
                        Deleted: user.Deleted,
                        DeleteDate: user.DeleteDate
                    }); 
                });
            }
            else callback();
        });
    }
    else callback();
});

但是,我已经搜索了包括此站点在内的示例和文档:

https://www.windowsazure.com/en-us/develop/nodejs/

但没有遇到任何提到延续令牌的东西。

任何帮助或建议将不胜感激。

4

3 回答 3

3

根据来源(第 481 行),如果存在延续令牌,则“queryEntitiesResultContinuation”属性将添加到您的结果中:

https://github.com/WindowsAzure/azure-sdk-for-node/blob/master/lib/services/table/tableservice.js

这有一个名为“getNextPage”的函数,它接受一个回调:

https://github.com/WindowsAzure/azure-sdk-for-node/blob/master/lib/services/table/models/queryentitiesresultcontinuation.js

您可能应该创建一个单独的函数来处理查询结果。此函数将遍历实体,然后检查是否设置了“queryEntitiesResultContinuation”。如果是这样,请调用该函数,将您的新函数作为回调传递。

我实际上没有尝试过,也找不到任何代码示例!

更新

以下是使用节点处理延续令牌的代码示例:

var tableService = require("azure").createTableService();

function queryWithContinuation(query, cb) {
    tableService.queryEntities(query, function(error, entities, continuationToken){
        if (continuationToken.nextPartitionKey) { 
            nextPage(entities, continuationToken, cb);
        } else {
            cb(entities);                    
        }
    });
}

// used to recursively retrieve the results
function nextPage(entities, continuationToken, cb){
    continuationToken.getNextPage(function(error, results, newContinuationToken){
        entities = entities.concat(results);
        if (newContinuationToken.nextPartitionKey){
            nextPage(entities, newContinuationToken, cb);
        } else {
            cb(entities);
        }
    });
}

// example usage
var query = azure.TableQuery.select().from('really-big-table');
queryWithContinuation(query, function(results){
    console.log(results);
});
于 2012-05-18T09:01:20.113 回答
0

我不熟悉 node.js。但是即使客户端库不支持延续令牌,我们仍然可以手动发出 HTTP 请求。http://nodejs.org/api/https.html#https_https_get_options_callback上的文档告诉我们如何从 node.js 发出 HTTP 请求,以及http://msdn.microsoft.com/en-us/library/上的文档windowsazure/dd135718告诉我们如何使用 HTTP 请求使用延续令牌。将它们结合起来,场景将起作用。Richard 可能会提供有关如何使用 Windows Azure node.js 客户端库的更多信息,这可能会使该过程更容易。

最好的祝福,

明旭。

于 2012-05-21T07:27:05.923 回答
0

如果有人使用我已经编写了一个帮助模块来遍历延续令牌。

请参阅https://github.com/freakyfriday/azure-storage-extension

//Usage

//create azure table service 
var tableService = azure.createTableService("AZURE_STORAGE_ACCOUNT","AZURE_STORAGE_ACCESS_KEY");

//query 
var myQuery = new azure.TableQuery().where(whereClause);

//get data automatically retrieving data where there is a continuation token 
tableService.queryEntitiesContinuation('Table', myQuery, null, function (error, result) { 
var allResults = result.entries; });

//module (place in separate file)
var azure = require('azure-storage');

azure.TableService.prototype.queryEntitiesContinuation = function (tableName, query, maxContinuationCount, callback) {

var tableService = this;
var data = new Array();
var countinuationCount = 0;
var operation = function (tableName, query, continuationToken) {
    tableService.queryEntities(tableName, query, continuationToken, function (error, result) {

        if (!error) {
            if (result.continuationToken) {

                result.entries.forEach(function (entry) {
                    data.push(entry);
                });

                if (maxContinuationCount === null || countinuationCount < maxContinuationCount) {
                    ++countinuationCount;
                    //update top
                    if (query._top !== null) {
                        query._top = query._top - data.length;
                        if (query._top !== 0) {
                            operation(tableName, query, result.continuationToken);
                        } else {
                            callback(error, result);
                        }
                    } else {
                        operation(tableName, query, result.continuationToken);
                    }
                } else {
                    callback(error, result);
                }

                
            } else {

                data.forEach(function (entry) {
                    result.entries.push(entry)
                });

                callback(error, result);
            }
        } else {

            result.entries.push(data);
            callback(error, result);
        }
    });
};

operation(tableName, query, null);
};

module.exports = azure;

于 2015-02-19T07:25:23.283 回答