本文整理汇总了C#中Amazon.SQS.AmazonSQSClient.GetQueueAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# AmazonSQSClient.GetQueueAttributes方法的具体用法?C# AmazonSQSClient.GetQueueAttributes怎么用?C# AmazonSQSClient.GetQueueAttributes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Amazon.SQS.AmazonSQSClient
的用法示例。
在下文中一共展示了AmazonSQSClient.GetQueueAttributes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetQueueArn
public virtual string GetQueueArn(AmazonSQSClient sqsClient, string queueUrl)
{
string queueArn;
// Construct a GetQueueAttributesRequest for the URL to retrieve the ARN
var getQueueAttributesRequest = new GetQueueAttributesRequest
{
QueueUrl = queueUrl,
AttributeNames =
{
"QueueArn"
}
};
// Submit the request
GetQueueAttributesResponse getQueueAttributesResponse =
sqsClient.GetQueueAttributes(getQueueAttributesRequest);
// Add the discovered ARN to the queueArnList variable.
queueArn = getQueueAttributesResponse.QueueARN;
return queueArn;
}
示例2: WindowCallback
/// <summary>
/// Callback for windowing the SQS messages ordered by time queued
/// </summary>
/// <param name="state"></param>
private void WindowCallback(Object state)
{
try
{
CancellationToken ct = (CancellationToken)state;
List<Message> messages = new List<Message>();
// syncronize the processing of windows
if ((!ct.IsCancellationRequested) &
(Monitor.TryEnter(_windowLock, 1000)))
{
try
{
long epochWindowTime = ToEpochTimeInMilliseconds(DateTime.UtcNow.Subtract(this.SQSWindow));
int numberOfMessages = 0;
// 1st query to determine the # of Messages available in the queue
using (AmazonSQSClient client = new AmazonSQSClient(
this.AWSAccessKey, this.AWSSecretAccessKey,
new AmazonSQSConfig() { ServiceURL = this.AWSSQSServiceUrl }))
{
// get the NumberOfMessages to optimize how to Receive all of the messages from the queue
GetQueueAttributesRequest attributesRequest = new GetQueueAttributesRequest();
attributesRequest.QueueUrl = this.QueueUrl;
attributesRequest.AttributeName.Add("ApproximateNumberOfMessages");
numberOfMessages = client.GetQueueAttributes(attributesRequest).GetQueueAttributesResult.ApproximateNumberOfMessages;
}
// determine if we need to Receive messages from the Queue
if (numberOfMessages > 0)
{
if (numberOfMessages < 10)
{
// just do it inline it's less expensive than spinning threads
ReceiveTask(ct, numberOfMessages);
}
else
{
// use the default partitioner to determine the number of tasks
// TODO Create a custom partitioner that takes into account the batch x 10 of SQS
Parallel.ForEach(Partitioner.Create(0, numberOfMessages),
(range) => ReceiveTask(ct, range.Item2 - range.Item1));
}
}
// ok so all messages have been Receieved and ordered or no more messages can be popped
if (!ct.IsCancellationRequested)
{
// get all messages less than the window time from the rb tree
// probably don't have to lock on _setLock because of the _windowLock but let's be safe
lock (_setLock)
{
messages.AddRange(_set.Where((m) => long.Parse(m.Attribute[0].Value) < epochWindowTime));
_set.RemoveWhere((m) => long.Parse(m.Attribute[0].Value) < epochWindowTime);
}
// remove duplicates
//TODO Find a better way to dedup that doesn't destroy the order of the array
IEnumerable<Message> dedupMessages = messages.Distinct(new MessageEqualityComparer());
// distinct doesn't presever order so we need to reorder the window
IEnumerable<Message> orderedMessages = dedupMessages.OrderBy(m => m, new MessageSentTimeStampComparer());
// raise the WindowEvent with the results
if (!ct.IsCancellationRequested)
{
OnNewWindow(dedupMessages);
}
}
}
finally
{
Monitor.Exit(_windowLock);
}
}
// check if we should delete the messages
if ((!ct.IsCancellationRequested) &
(messages.Count > 0))
{
if (messages.Count < 10)
{
DeleteTask(ct, messages, new Tuple<int, int>(0, messages.Count));
}
else
{
// use the default partitioner to determine the number of tasks
// TODO Create a custom partitioner that takes into account the batch x 10 of SQS
Parallel.ForEach(Partitioner.Create(0, messages.Count),
(range) => DeleteTask(ct, messages, range));
}
}
}
catch (Exception ex)
{
//.........这里部分代码省略.........
示例3: MessageDeleted
public void MessageDeleted()
{
AddConfigValue("SQSWindow", "0.00:00:15");
int visibilityTimeout = -1;
// change the visibility timeout of the queue
using (Amazon.SQS.AmazonSQSClient client = new AmazonSQSClient(
ConfigurationManager.AppSettings["AWSAccessKey"],
ConfigurationManager.AppSettings["AWSSecretAccessKey"],
new AmazonSQSConfig()))
{
// store the visibilitytimeout so we can reset it
GetQueueAttributesRequest getRequest = new GetQueueAttributesRequest();
getRequest.QueueUrl = ConfigurationManager.AppSettings["QueueUrl"];
getRequest.AttributeName.Add("VisibilityTimeout");
GetQueueAttributesResponse response = client.GetQueueAttributes(getRequest);
visibilityTimeout = response.GetQueueAttributesResult.VisibilityTimeout;
// set it to 1 second
SetQueueAttributesRequest setRequest = new SetQueueAttributesRequest();
setRequest.QueueUrl = ConfigurationManager.AppSettings["QueueUrl"];
setRequest.Attribute.Add(new Amazon.SQS.Model.Attribute() { Name = "VisibilityTimeout", Value = "1" });
client.SetQueueAttributes(setRequest);
String[] messageIds = new String[] { QueueMessage() };
MockSQSService service = new MockSQSService();
service.Start();
PollForMessages(messageIds, service);
ReceiveMessageRequest receiveRequest = new ReceiveMessageRequest();
receiveRequest.QueueUrl = ConfigurationManager.AppSettings["QueueUrl"];
ReceiveMessageResponse receiveResponse = client.ReceiveMessage(receiveRequest);
Assert.AreEqual(0, receiveResponse.ReceiveMessageResult.Message.Where((m) => m.MessageId == messageIds[0]).Count());
// set the visibility timeout back
setRequest = new SetQueueAttributesRequest();
setRequest.QueueUrl = ConfigurationManager.AppSettings["QueueUrl"];
setRequest.Attribute.Add(new Amazon.SQS.Model.Attribute() { Name = "VisibilityTimeout", Value = visibilityTimeout.ToString() });
client.SetQueueAttributes(setRequest);
RemoveConfigValue("SQSWindow");
}
}
示例4: SQSGetQueueAttributes
public static void SQSGetQueueAttributes()
{
#region SQSGetQueueAttributes
var client = new AmazonSQSClient();
var request = new GetQueueAttributesRequest
{
QueueUrl = "https://sqs.us-east-1.amazonaws.com/80398EXAMPLE/MyTestQueue",
AttributeNames = new List<string>() { "All" }
};
var response = client.GetQueueAttributes(request);
Console.WriteLine("Attributes for queue ARN '" + response.QueueARN + "':");
Console.WriteLine(" Approximate number of messages:" +
response.ApproximateNumberOfMessages);
Console.WriteLine(" Approximate number of messages delayed: " +
response.ApproximateNumberOfMessagesDelayed);
Console.WriteLine(" Approximate number of messages not visible: " +
response.ApproximateNumberOfMessagesNotVisible);
Console.WriteLine(" Queue created on: " + response.CreatedTimestamp);
Console.WriteLine(" Delay seconds: " + response.DelaySeconds);
Console.WriteLine(" Queue last modified on: " +
response.LastModifiedTimestamp);
Console.WriteLine(" Maximum message size: " +
response.MaximumMessageSize);
Console.WriteLine(" Message retention period: " +
response.MessageRetentionPeriod);
Console.WriteLine(" Visibility timeout: " + response.VisibilityTimeout);
Console.WriteLine(" Policy: " + response.Policy);
Console.WriteLine(" Attributes:");
foreach (var attr in response.Attributes)
{
Console.WriteLine(" " + attr.Key + ": " + attr.Value);
}
#endregion
Console.ReadLine();
}
示例5: QueueLengthByQueueUrl
public static int QueueLengthByQueueUrl(string queueUrl)
{
using (var client = new AmazonSQSClient(Settings.AccessKey, Settings.Secret))
{
var request = new GetQueueAttributesRequest
{
QueueUrl = queueUrl,
AttributeNames = new List<string> { "ApproximateNumberOfMessages" }
};
return client.GetQueueAttributes(request).ApproximateNumberOfMessages;
}
}