Reputation: 175
I have list of over 20 queues that needs to be added as private queue in MSMQ.
Is there a way to do it using
Command Line
C# programming
If there is a way to do using some sort of script or .net programming then I could add it with out manually inputting it and causing typos.
Please let me know.
thanks
Upvotes: 11
Views: 10549
Reputation: 35477
using System.Messaging;
//...
void CreateQueue(string qname) {
if (!MessageQueue.Exists(qname)) MessageQueue.Create(qname);
}
You can only create private queues on your local computer. For more information see: Creating Queues
Upvotes: 19
Reputation: 310
A bit late on this, however I only started working on them now.
To add to Richard's answer, you can create public queues. you need the hostname though and admin access to that machine.
public static MessageQueue CreatePrivate(string name) {
string path = string.Format(@".\private$\{0}", name);
if (!MessageQueue.Exists(path)) {
MessageQueue.Create(path);
return new MessageQueue(path);
}
return new MessageQueue(path);
}
public static MessageQueue CreatePublic(string hostname,string queuename) {
string path = string.Format(@"{0}\{1}", hostname,queuename);
if (!MessageQueue.Exists(path)) {
MessageQueue.Create(path);
return new MessageQueue(path);
}
return new MessageQueue(path);
}
}
Upvotes: 0
Reputation: 3807
For command line, you can create a .vbs file with following content:
Option Explicit
Dim objInfo
Dim objQue
Dim objMsg
Dim strFormatName ' Destination
strFormatName = "direct=os:.\private$\test"
Set objInfo = CreateObject("MSMQ.MSMQQueueInfo")
Set objMsg = CreateObject("MSMQ.MSMQMessage")
objMsg.Label = "my message"
objMsg.Body = "This is a sample message."
objInfo.FormatName = strFormatName
set objQue = objInfo.Open( 2, 0 )
' Send Message
objMsg.Send objQue
' Close Destination
objQue.Close
Set objMsg = Nothing
Set objInfo = Nothing
msgbox "Done..."
Upvotes: 2