Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

AWS: Simple Queue Servié sus Message queues provide communication and coordinati

ID: 3737019 • Letter: A

Question

AWS: Simple Queue Servié sus Message queues provide communication and coordination for these distributed applications. Message performance, reliability and scalability while improving queues can significantly simplify coding of decoupled applications, SQS Types: I-requests (The message will be stored for 4 days but you can changed up to 14 days) 2- Replies (deleted directly) 3-error messages can handle up to 5 messages a day (reset every day 4-plain information unlimited Message Attribute Items and Validation Each message attribute consists of the following items: Name-The message attribute name can contain the following characters: A-Z, a- z, e-9, underscore ), hyphen(-), and period (.). The name must not start or end with a period, and it should not have successive periods. The name is case- sensitive and must be unique among all attribute names for the message. The name can be up to 256 characters long. The name can't start with ANS. or Amazon. (or any variations in casing) because these prefixes are reserved for use by Amazon Web Services Type-The supported message attribute data types are String, Number, and Binary. You can also provide custom information about the type. The data type has the same restrictions on the content as the message body. The data type is case-sensitive, and it can be up to 256 bytes long Value-The user-specified message attribute value. For string data types, the value attribute has the same restrictions on the content as the message body . . Date . Time month Write a program to print the status of all queues at the end of the month (assuming that the queues were all empty at the beginning of the month),

Explanation / Answer

private MessageQueue _messageQueue;

private int CountCursor()

{

_messageQueue = new MessageQueue(".\private$\pingpong", QueueAccessMode.Peek);

int count = 0;

Cursor cursor = _messageQueue.CreateCursor();

Message m = CursorPeekWithoutTimeout(cursor, PeekAction.Current);

if (m != null)

{

count = 1;

while ((m = CursorPeekWithoutTimeout(cursor, PeekAction.Next)) != null)

{

count++;

}

if (m != null) m.Dispose();

}

cursor.Dispose();

return count;

}

protected Message CursorPeekWithoutTimeout(Cursor cursor, PeekAction action)

{

Message ret = null;

try

{

ret = _messageQueue.Peek(new TimeSpan(1), cursor, action);

}

catch (MessageQueueException mqe)

{

if (mqe.MessageQueueErrorCode != MessageQueueErrorCode.IOTimeout)

{

throw;

}

}

return ret;

}

GetAllMessages returns a static copy of the messages in the queue, this is fine for small one off counts. In the real world you could have several hundred thousand large messages in the queue so to reduce the amount of information bought back we need to set up a message filter. The more messages you have in your queue the longer this method will take to count.

var _messageQueue = new MessageQueue(".\private$pingpong", QueueAccessMode.Peek);

var countFilter = new MessagePropertyFilter

{

AdministrationQueue = false,

ArrivedTime = false,

CorrelationId = false,

Priority = false,

ResponseQueue = false,

SentTime = false,

Body = false,

Label = false,

Id = false

};

_messageQueue.MessageReadPropertyFilter = countFilter;

return _messageQueue.GetAllMessages().Length;

GetEnumerator2 returns a dynamic list of messages in the queue. The more messages you have in your queue the longer this method will take to count.

var _messageQueue = new MessageQueue(".\private$pingpong", QueueAccessMode.Peek);

var x = _messageQueue.GetMessageEnumerator2();

int iCount = 0;

while (x.MoveNext())

{

   iCount++;

}

return iCount;

PowerShell (WMI) Method

This is by fastest method by far taking about 20ms regardless of how may messages there are to count. This is the only method for counting the message queues on other machines that you have access to.

private int GetPowerShellCount()

{

return GetPowerShellCount(".\private$pingpong", Environment.MachineName, "", "");

}

private int GetPowerShellCount(string queuePath, string machine,string username, string password)

{

var path = string.Format(@"\{0} ootCIMv2", machine);

ManagementScope scope;

if (string.IsNullOrEmpty(username))

{

scope = new ManagementScope(path);

}

else

{

var options = new ConnectionOptions {Username = username, Password = password};

scope = new ManagementScope(path, options);

}

scope.Connect();

if (queuePath.StartsWith(".\")) queuePath=queuePath.Replace(".\",string.Format("{0}\",machine));

  

string queryString = String.Format("SELECT * FROM Win32_PerfFormattedData_msmq_MSMQQueue");

var query = new ObjectQuery(queryString);

var searcher = new ManagementObjectSearcher(scope, query);

IEnumerable<int> messageCountEnumerable =

from ManagementObject queue in searcher.Get()

select (int)(UInt64)queue.GetPropertyValue("MessagesInQueue");

//IEnumerable<string> messageCountEnumerable =

// from ManagementObject queue in searcher.Get()

// select (string)queue.GetPropertyValue("Name");

var x = messageCountEnumerable.First();

return x;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote