|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionThe goal of this article is to explain the process of creating an ASP.NET project that allows privileged users to dynamically delete messages from Microsoft Message Queue (MSMQ). There are many reasons to build this tool. Few of the primary reasons are as below:
BackgroundThis article assumes readers' familiarity with MSMQ. If you are not familiar with MSMQ, you may want to research on it before you proceed. You may want to concentrate on topics like what is MSMQ, how to install and create queues, types of queues, accessing the queues and setting permissions to programmatically access the queue. You specifically want to read for private queues. For more details, I strongly recommend visiting this link. (This link is active as of now, but if it is ever broken you can Google MSMQ or read about it on MSDN.) Using the CodeSolution name: DQC (stands for Delete Queue Contents). This solution contains five files around two projects (DQC and QMsngr):
Basic Setup
Contents of the DQConfig.xml<!-- Created for public use -->
<!-- For Educational purpose only -->
<!-- Contains the password. Restrict access for the file to Admins -->
<?xml version="1.0" encoding="utf-8" ?>
<root>
<items>
<item> Admin Request </item>
<item> QA Request </item>
<item> Mgmt Request </item>
<item> Environment Request </item>
<item> Upgrade/Maintenance </item>
<item> Other </item>
</items>
<access>
<password>codeproject</password>
</access>
</root>
DelRecords Table in DQC.mdb
Using the Code QMsngr.csUsing the QMsngr.exe, we send messages to our recently created queue. Let’s dig into the QMsngr project: // This is partial code from “QMsngr.cs” file
MessageQueue testQ = new MessageQueue(".\\Private$\\TestQueue");
Message msg = new Message();
for (int msgCount = 1 ; msgCount <= 5; msgCount++)
{
msg.Label = "Test Message " + msgCount.ToString();
msg.Body = "This is body of Message" + msgCount.ToString() +
" The quick brown fox jumps over the lazy dog";
testQ.Send(msg);
}
Console.WriteLine("Transmission Complete");
We connect to the queue called TestQueue and send five messages to the queue; each with label Test Message <Number> and body This is body of Message <Message number> The quick brown fox jumps over the lazy dog. After the messages are sent to the queue, we display Transmission Complete on the screen. Using the CodeDQCMain.aspxCreating the table - creating the first row is done in the We calculate the number of rows required by iterating through the Message Queue and counting the number of messages. Total Number of the rows in the table = 1 Header Row + Total Number of Messages. As we are iterating, we call the c.Controls.Add(new LiteralControl("<a href = MsgDetails.aspx?txtMsgId="+
msgId +">" + msgLabel));
MsgDetails.aspxThe MsgDetails.aspx has information about the selected message. It has details like MessageID, Proprity, Sent Time, Body, and reason of deletion. Specific details about the message can be added as per the design. In the txtMsgId.Text = Request["txtMsgId"];
We populate the drop down list which states the reason for deleting the message in the code that follows. The DQConfig.xml contains all the details. DataSet dataDoc = new DataSet();
dataDoc.ReadXml("C:\\DQC\\DQConfig.xml");
// Some Code
We reset the message queue cursor and iterate through the queue to find a match. Once the match is found, the message is identified and the details are retrieved and displayed in the appropriate server controls. queueEnum.Reset();
while(queueEnum.MoveNext())
{
if(queueEnum.Current.Id == txtMsgId.Text)
{
// Some Code
break;
}
}
Users need to enter a password before they can delete message(s) from the queue. When the user clicks on the button Remove or Remove All, the password is verified and the current message is deleted from the queue and all the necessary details are added to the database.
Points of Interest:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||