本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Queue.CloudQueue.PeekMessageAsync方法的典型用法代码示例。如果您正苦于以下问题:C# CloudQueue.PeekMessageAsync方法的具体用法?C# CloudQueue.PeekMessageAsync怎么用?C# CloudQueue.PeekMessageAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.WindowsAzure.Storage.Queue.CloudQueue
的用法示例。
在下文中一共展示了CloudQueue.PeekMessageAsync方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BasicQueueOperationsAsync
private static async Task BasicQueueOperationsAsync(CloudQueue queue)
{
Console.WriteLine("2. Insert a single message into a queue");
await queue.AddMessageAsync(new CloudQueueMessage("Hello World!"));
Console.WriteLine("3. Peek at the next message");
CloudQueueMessage peekedMessage = await queue.PeekMessageAsync();
if (peekedMessage != null)
{
Console.WriteLine("The peeked message is: {0}", peekedMessage.AsString);
}
Console.WriteLine("4. De-queue the next message");
CloudQueueMessage message = await queue.GetMessageAsync();
if (message != null)
{
Console.WriteLine("Processing & deleting message with content: {0}", message.AsString);
await queue.DeleteMessageAsync(message);
}
}
示例2: QueueRegionalSASTestAsync
public async Task QueueRegionalSASTestAsync()
{
#if ASPNET_K
//CultureInfo currentCulture = CultureInfo.CurrentCulture;
//CultureInfo.CurrentCulture = new CultureInfo("it");
#else
string currentPrimaryLanguage = ApplicationLanguages.PrimaryLanguageOverride;
ApplicationLanguages.PrimaryLanguageOverride = "it";
#endif
CloudQueueClient client = GenerateCloudQueueClient();
CloudQueue queue = client.GetQueueReference(GenerateNewQueueName());
try
{
await queue.CreateAsync();
string messageContent = Guid.NewGuid().ToString();
CloudQueueMessage message = new CloudQueueMessage(messageContent);
await queue.AddMessageAsync(message);
// Prepare SAS authentication with full permissions
string id = Guid.NewGuid().ToString();
DateTime start = DateTime.UtcNow;
DateTime expiry = start.AddMinutes(30);
QueuePermissions permissions = new QueuePermissions();
SharedAccessQueuePermissions queuePerm = SharedAccessQueuePermissions.Add | SharedAccessQueuePermissions.ProcessMessages | SharedAccessQueuePermissions.Read | SharedAccessQueuePermissions.Update;
permissions.SharedAccessPolicies.Add(id, new SharedAccessQueuePolicy()
{
SharedAccessStartTime = start,
SharedAccessExpiryTime = expiry,
Permissions = queuePerm
});
await queue.SetPermissionsAsync(permissions);
await Task.Delay(30 * 1000);
string sasTokenFromId = queue.GetSharedAccessSignature(null, id);
StorageCredentials sasCredsFromId = new StorageCredentials(sasTokenFromId);
CloudQueue sasQueueFromId = new CloudQueue(queue.Uri, sasCredsFromId);
CloudQueueMessage receivedMessage1 = await sasQueueFromId.PeekMessageAsync();
Assert.AreEqual(messageContent, receivedMessage1.AsString);
string sasTokenFromPolicy = queue.GetSharedAccessSignature(permissions.SharedAccessPolicies[id], null);
StorageCredentials sasCredsFromPolicy = new StorageCredentials(sasTokenFromPolicy);
CloudQueue sasQueueFromPolicy = new CloudQueue(queue.Uri, sasCredsFromPolicy);
CloudQueueMessage receivedMessage2 = await sasQueueFromPolicy.PeekMessageAsync();
Assert.AreEqual(messageContent, receivedMessage2.AsString);
}
finally
{
#if ASPNET_K
//CultureInfo.CurrentCulture = currentCulture;
#else
ApplicationLanguages.PrimaryLanguageOverride = currentPrimaryLanguage;
#endif
queue.DeleteAsync().AsTask().Wait();
}
}
示例3: UpdateQueueSASTestAsync
public async Task UpdateQueueSASTestAsync()
{
CloudQueueClient client = GenerateCloudQueueClient();
CloudQueue queue = client.GetQueueReference(GenerateNewQueueName());
try
{
await queue.CreateAsync();
string messageContent = Guid.NewGuid().ToString();
CloudQueueMessage message = new CloudQueueMessage(messageContent);
await queue.AddMessageAsync(message);
SharedAccessQueuePolicy policy = new SharedAccessQueuePolicy()
{
SharedAccessStartTime = DateTimeOffset.UtcNow.AddMinutes(-5),
SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(30),
Permissions = SharedAccessQueuePermissions.Add | SharedAccessQueuePermissions.ProcessMessages,
};
string id = Guid.NewGuid().ToString();
string sasToken = queue.GetSharedAccessSignature(policy, null);
StorageCredentials sasCreds = new StorageCredentials(sasToken);
CloudQueue sasQueue = new CloudQueue(queue.Uri, sasCreds);
OperationContext context = new OperationContext();
await TestHelper.ExpectedExceptionAsync(
async () => await sasQueue.PeekMessageAsync(null, context),
context,
"Peek when Sas does not allow Read access on the queue",
HttpStatusCode.Forbidden);
await sasQueue.AddMessageAsync(message);
SharedAccessQueuePolicy policy2 = new SharedAccessQueuePolicy()
{
SharedAccessStartTime = DateTimeOffset.UtcNow.AddMinutes(-5),
SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(30),
Permissions = SharedAccessQueuePermissions.Add | SharedAccessQueuePermissions.ProcessMessages | SharedAccessQueuePermissions.Read,
};
string sasToken2 = queue.GetSharedAccessSignature(policy2, null);
sasCreds.UpdateSASToken(sasToken2);
sasQueue = new CloudQueue(queue.Uri, sasCreds);
await sasQueue.PeekMessageAsync();
}
finally
{
queue.DeleteIfExistsAsync().AsTask().Wait();
}
}
示例4: QueueSASTestAsync
public async Task QueueSASTestAsync()
{
CloudQueueClient client = GenerateCloudQueueClient();
CloudQueue queue = client.GetQueueReference(GenerateNewQueueName());
await queue.CreateAsync();
string messageContent = Guid.NewGuid().ToString();
CloudQueueMessage message = new CloudQueueMessage(messageContent);
await queue.AddMessageAsync(message);
// Prepare SAS authentication with full permissions
string id = Guid.NewGuid().ToString();
DateTime start = DateTime.UtcNow;
DateTime expiry = start.AddMinutes(30);
QueuePermissions permissions = new QueuePermissions();
SharedAccessQueuePermissions queuePerm = SharedAccessQueuePermissions.Add | SharedAccessQueuePermissions.ProcessMessages | SharedAccessQueuePermissions.Read | SharedAccessQueuePermissions.Update;
permissions.SharedAccessPolicies.Add(id, new SharedAccessQueuePolicy()
{
SharedAccessStartTime = start,
SharedAccessExpiryTime = expiry,
Permissions = queuePerm
});
await queue.SetPermissionsAsync(permissions);
await Task.Delay(30 * 1000);
string sasTokenFromId = queue.GetSharedAccessSignature(null, id);
StorageCredentials sasCredsFromId = new StorageCredentials(sasTokenFromId);
CloudStorageAccount sasAcc = new CloudStorageAccount(sasCredsFromId, null /* blobEndpoint */, new Uri(TestBase.TargetTenantConfig.QueueServiceEndpoint), null /* tableEndpoint */, null /* fileEndpoint */);
CloudQueueClient sasClient = sasAcc.CreateCloudQueueClient();
CloudQueue sasQueueFromSasUri = new CloudQueue(sasClient.Credentials.TransformUri(queue.Uri));
CloudQueueMessage receivedMessage = await sasQueueFromSasUri.PeekMessageAsync();
Assert.AreEqual(messageContent, receivedMessage.AsString);
CloudQueue sasQueueFromSasUri1 = new CloudQueue(new Uri(queue.Uri.ToString() + sasTokenFromId));
CloudQueueMessage receivedMessage1 = await sasQueueFromSasUri1.PeekMessageAsync();
Assert.AreEqual(messageContent, receivedMessage1.AsString);
CloudQueue sasQueueFromId = new CloudQueue(queue.Uri, sasCredsFromId);
CloudQueueMessage receivedMessage2 = await sasQueueFromId.PeekMessageAsync();
Assert.AreEqual(messageContent, receivedMessage2.AsString);
string sasTokenFromPolicy = queue.GetSharedAccessSignature(permissions.SharedAccessPolicies[id], null);
StorageCredentials sasCredsFromPolicy = new StorageCredentials(sasTokenFromPolicy);
CloudQueue sasQueueFromPolicy = new CloudQueue(queue.Uri, sasCredsFromPolicy);
CloudQueueMessage receivedMessage3 = await sasQueueFromPolicy.PeekMessageAsync();
Assert.AreEqual(messageContent, receivedMessage3.AsString);
await queue.DeleteAsync();
}
示例5: QueueSASTestAsync
public async Task QueueSASTestAsync()
{
CloudQueue queue = DefalutQueueClient.GetQueueReference(TestHelper.GenerateNewQueueName());
await queue.CreateAsync();
string messageContent = Guid.NewGuid().ToString();
CloudQueueMessage message = new CloudQueueMessage(messageContent);
await queue.AddMessageAsync(message);
// Prepare SAS authentication with full permissions
string id = Guid.NewGuid().ToString();
DateTime start = DateTime.UtcNow;
DateTime expiry = start.AddMinutes(30);
QueuePermissions permissions = new QueuePermissions();
SharedAccessQueuePermissions queuePerm = SharedAccessQueuePermissions.Add | SharedAccessQueuePermissions.ProcessMessages | SharedAccessQueuePermissions.Read | SharedAccessQueuePermissions.Update;
permissions.SharedAccessPolicies.Add(id, new SharedAccessQueuePolicy()
{
SharedAccessStartTime = start,
SharedAccessExpiryTime = expiry,
Permissions = queuePerm
});
await queue.SetPermissionsAsync(permissions);
await Task.Delay(30 * 1000);
string sasTokenFromId = queue.GetSharedAccessSignature(null, id);
StorageCredentials sasCredsFromId = new StorageCredentials(sasTokenFromId);
CloudQueue sasQueueFromId = new CloudQueue(queue.Uri, sasCredsFromId);
CloudQueueMessage receivedMessage1 = await sasQueueFromId.PeekMessageAsync();
Assert.AreEqual(messageContent, receivedMessage1.AsString);
string sasTokenFromPolicy = queue.GetSharedAccessSignature(permissions.SharedAccessPolicies[id], null);
StorageCredentials sasCredsFromPolicy = new StorageCredentials(sasTokenFromPolicy);
CloudQueue sasQueueFromPolicy = new CloudQueue(queue.Uri, sasCredsFromPolicy);
CloudQueueMessage receivedMessage2 = await sasQueueFromPolicy.PeekMessageAsync();
Assert.AreEqual(messageContent, receivedMessage2.AsString);
await queue.DeleteAsync();
}