Library tutorials & articles
Get the Message - MSMQ
Recieving a Message
On the receiving side of the message queue must be an application that takes the incoming message and processes it. The code below illustrates how to accomplish this task.
Private Sub ReceiveMessage()
Dim QI as New MSMQQueueInfo
Dim ReceiveQ As MSMQQueue
Dim msg As MSMQMessage
QI.PathName = "MyServer\QueueName"
Set ReceiveQ = QI.Open(MQ_RECEIVE_ACCESS, MQ_DENY_NONE)
Set msg = ReceiveQ.Receive(ReceiveTimeout:=1000)
If msg is Nothing Then
MsgBox "No message was received"
Else
' Code to process the message goes here
End If
ReceiveQ.Close
End Sub
The only significant difference between this example and the one used to send
a message is the Receive method. It takes a parameter that indicates how long
the function should wait if no message exists in the message queue. In this example,
we are waiting for 1000 milliseconds or one second. If the function returns a
valid MSMQMessage object, then we can process the body as we wish. Otherwise,
the function returns a null reference (identified by the 'Is Nothing' check).
A ReceiveTimeout value of 0 means that no waiting will occur. A value of -1 means
that the function will block until a message is received.
Related articles
Related discussion
-
Run-time error '91'
by converter2009 (1 replies)
-
VB6 Runtime error 381 subsript out of range Error
by Uncle (2 replies)
-
passing and reading parameters from using Shell
by jigartoliya (0 replies)
-
Convert C++ code to VB6
by mawcot (4 replies)
-
listbox scrollbar
by Dennijr (10 replies)
Related podcasts
-
Christian Beauclair
14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...
I am using MSMQ-3 on my local machine. I am using enableNotification method to notify me when a message comes in the queue. But i am getting error message while using enableNotification. The message comes is "Access is denied" (error no. -1072824283). I am getting the message in the following line
Dim evnt As MSMQ.MSMQEvent
evnt = New MSMQ.MSMQEvent
vMyQSend.EnableNotification(evnt)
Please anybody help me.
Ummm, there's a lot of other stuff around the code that I have (which was in a VB.DLL used within ASP pages), but I tried to pull out the working code that would get to the essence of what you need. Essentially, this code opens a queue, creates a message on the queue, sets the body of the message, then sends the message. We developed another module which gets back the Id from the message sent so we use that to track the status of the send. Not sure if it works, but it's pretty close ... maybe I left something off, but this is code that has been working for the last several years ... having generated hundreds of thousands of messages. If you have any questions, or want some ideas on some more complicated stuff we put around it for sending and checking results, let me know at henry @ dcbiking . com
>> Henry
Dim oDOM As MSXML2.DOMDocument 'Holds XML to be sent
Dim oQueueInfo As MSMQ.MSMQQueueInfo 'Used to return the queue info for formatting message props.
Dim oQueue As MSMQ.MSMQQueue 'Queue
Dim oMsg As MSMQ.MSMQMessage 'Message to be placed on queue
Set oQueueInfo = CreateObject("MSMQ.MSMQQueueInfo")
oQueueInfo.Pathname = "MACHINENAME\PATHNAMEBLAHBLAH"
Set oQueue = oQueueInfo.Open(MSMQ.MQSENDACCESS, MSMQ.MQDENYNONE)
Set oDOM = Server.CreateObject("MSXML2.DOMDocument")
oDOM.loadXML = "<call><sendTo>user@user.com</sendTo><method>Sum</method><parms><parm>1</parm><parm>2</parm></parms></call>"
' Create message
If oQueue.IsOpen Then
Set oMsg = CreateObject("MSMQ.MSMQMessage")
oMsg.Body = oDOM.xml
Else
Err.Raise 203, "sendRequest", "MSMQ queue could not be opened to send the message."
End If
' Send message
'Message sending will accommodate both transactional and non-transactional queues.
'If the queue is transactional, send the message with the single message option.
'If the queue is not transactional, send the message as non-transactional.
If oQueueInfo.IsTransactional Then
oMsg.Send oQueue, MQSINGLEMESSAGE
Else
oMsg.Send oQueue, MQNOTRANSACTION
End If
'Close queue; Null all objects
oQueue.Close
Set oMsg = Nothing
Set oQueue = Nothing
Set oQueueInfo = Nothing
Set oDOM = Nothing
Hi,
Could you please let me know, how to send an xml file as an object to a message queue? If possible can you provide me any code snippet for this as I'm novice to this technology.
Also, I want to receive this message as an XML file only.
Thanks in advance.
-CyberLotus
Hi,
I have similar error "The operation is not supported on a workgoup installation of computer" while testing MSMQ program. I am using VB6 to write the MSMQ program. Do you have any advise on how can I overcome it?
I also have problem determining the MSMQ server name and Queue name. Any idea where can I find these info. I have installed MSMQ and added reference to MSMQ 2.0 Object Library.
The syntax which you have posted seems to be for .NET version. Thanks in advance.
Regards
Thongfam
I need to Know hoy many messages are in a MSMQ Queue using API, WMI or OCX component using Visual Basic
Any Idea?
Gabriel
Dim q As New Messaging.MessageQueue("FormatName
A good example on how to get the Queues real path would be this
For Each queue As Messaging.MessageQueue In Messaging.MessageQueue.GetPrivateQueuesByMachine("RMPOSC-714")
messagebox.show(queue.Path)
Next
I have installed MSMQ on 2 Win2000 machines and have written a simple program to send a message from one to the other. I can successfully send a message from VB to my local machine with a pathname of ".\Private$\testq". However, when I attempt to cross the network to a known computer called RMPOSC-714 it fails the the error message below. This time I am setting pathname to "RMPOSC-714\testq".
The error is: -1072824214: The operation is not supported for a WORKGROUP installation.
Both PCs are on the network and in the domain.
What am I missing?
OK I've got the windows forms idea down. How can I send and receive from an ASP page. What I would like to be able to do is the following:
1. A user modifies data.
2. post the user change to the queue.
3. Have a listener pick up and process the user change.
4. Post to the queue a sucess.
5. return that sucuss to the user.
I have a problem with sept 2 and how to impliment.
Step 5 I have no idea on how to do this. It seems that I would need an additional listener that would pick up the return sucess message and would know what user to return it it. I am thinking that I will need some type of block on the ASP page that will wait until it receives an return....but how??
Best thing to do is byte[] .
Putting it into a string : look on your networksniffer : a lot of formatting data
(20h) gets included ! No ideal when the network is on heavy duty .
using SYSTEM.messaging, one could use the Body.bodystream to pump a filestream into the body of the message . Is it still available usder MSMQ API ? I cannot find it .
Furthermore, the explanation given below is very valuable for me . I have still one question, I do have to get rid of the unicode property : I cannot effort doubling the data on small radiolinks . In order to compare performance of MSMQ3.0 with other products (TIBCO RendezVous), I have to get UTB8 , ASCII ...
But the data coming from the layers above me is always XML-document . How can I accomplish ?
Perhaps bytestream ? But then again : no streamproperty for the messageBody ...
Documentation states that anything could be referred as the body of the MSMQMessage , as f.ex. an XML document . Would it be possible to give me a glimp of how you reference this object to enpack it in the body ?
I'm having problems with it . Thnks in advance .
We have an app working this way -
Web/MSMQ server creates a message packet in XML/DB2 format, wraps it using base64 algorithm and keeps it in outboundq of the web/msmq server. A trigger (MSMQ trigger) fires which will post (HTTPS) this data to supplier queues in a server around our premises which will unwrap it and insert into our AS/400 (using HitODBC). [We use this mechanism since a third party is hosting our server]
CRON services working on our local server picks data from the AS/400 and will send across to our web/msmq server using the same mechanism.
-Binoy
1) Set the Message's Body to the DOM's xml property
oMsg.Body = oDOM.xml
2) Send the message
3) After receiving/peek the message, loadXML from the oMsg.Body
oDOM.loadXML oMsg.Body
NOTE: The message body will be stored as Unicode, 2 bytes per character. So, if the msg is limited to 4MB in size, then effectively only 2MB of text (the oDOM.xml property) can be sent.
>> Henry
successfully sent as I could see the xml text in the body
If I knew that the body of the message was an XML document, I would receive the message as a string and then use the LoadXML method of the DOMDocument object to load it into the appropriate structure.
Your problem can be solved using datasets (.net). Check out this page from MSDN, "http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/secnetlpMSDN.asp?frame=true", I think it will help you out with your problem as long as you are using .NET.
The required environment is MSMQ Server installation on Windows Server machine, that's it. The advantage of this technology is to give a guarnateed delivery to the client even if the computer fail or get shut down because of some reason. The message keeps on sitting in the queue unless retreived successfully by the client, you can set various options like recoverable messages, acknowledgements etc. overall cool technology. Very easy to use with Visual Basic 6.0.
Sandeep
Do you have MSMQ Client installed on your machine? You need either MSMQ Client or Server on your machine to get this going, hope you would have set the reference to Microsoft MSMQ 2.0. Also you can connect to only a Public Queue from a client machine.
Good Luck
Sandeep
Hi,
I have tried with u r example.I have got Microsoft Message Queue 2.0 object library and i am getting an error "Active-x Component Can't Create Object" on executing "QI.PathName = "MyServer\QueueName"".What shall i do??
Bye
Hi,
I would like to know what can be achieved with MSMQ and its required environment.Can u pls help me in this regard??
Bye
Prakash
I am having a similar problem. Did you get any response from other people yet? I am quite interested.
Thanks.
Hi, I am developing an application using MSMQ. I tried sending an xml file as an object. It was successfully sent as I could see the xml text in the body of the message in the queue. However I am having problem in reading the body(Which has the xml file) once I peek or receive the message through VB code. I do not know what should be the datatype of the variable of the body at the receiving end. Any help or suggestions please?
Thanks in advance,
- VG
Hi,
Am trying to develop a web based application interacting with AS400. Would you please let me know how do I interact with DB2 on AS400 from my VB DLL/ ASP application?
Thank you
I have developed an MSMQ application that reads a file from the client end and sends it across onto the MSMQ server .The issue is that if the file size(bytes) is more than 2MB i am splitting them and sending it across.
My Question is
1) On the server end how do i collate these files and process them and send it back to the same client from where the splitted files were sent
2) On the client how do collate the files back and put it in a single file after the files processed are sent from the server.
Please help me out on the above lines as i am getting stuck on the same.
Also wanted to know if we can also send files other than text files.If so how???
Regards
Ganesh
Hello sir,
Could you please help me with following question:
Can private queues running on Windows 2000 Professional exchange messages OR is it necessary to have a MSMQ Server in the middle?
Thank you
Marina
Hello,Sir
My ultimate aim is that to provide User to save my application/form in as it is format
I've developed a project which i want it to be used by user as a software,which enables any user to
download on to their hard-drive whether they have a VB or not.My question is that my application which
i'd made to be saved on drive ( whole form/app. including backgroung color,textbx color....) It's exe.file
o.k now when i write any input or fill the content in my text-box it displays in plain format only &
i don't want this to happen;what i require is my exe.file should be saved as it is as i 've made. For
example you make a software in Vb regarding your personal diet chart withbackground-col, color txt-bx,col-labels,col-combobx
with picture bx,command button......fine then you convert this to exe.file;now if you want to launch
this software how can any user download this with all the details including the above mention list.Only
the thing where i've got stuck is saving my software/application;The important thing after converting
my application to exe.file it's in a same format with all those colors & other properties;but when i
write something in the textbx or combo-bx its displaying in plain format.This is where i need to explore
more & i expect that you'll provide me all the needed code function furthur required.Hope you'll guide
me.
actually i'd made a project regarding my teacher's profile where i've 1-form containing :-
This Form has background color which insert from properties->picture;also
labels,textbox,combo box are all in different color( properties->background).
Now when i save this form in this format which is stated above but when its saved
it is in plain text without picture.
Label Textbox
1)Teachers Name Text1
2)Subjects Text2
3)Email-id Combo-box & one Picture box
This above form also has 2-command buttons ( Saveas,Preview)
I've all the codings for all of this but i want to save my form in as it is format including colors & picture.
Below is the coding:
Private Sub Command1_Click() 'Preview button
Form2.Show
End Sub
Private Sub dir1_change()
File1.Path = Dir1.Path
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub
Private Sub File1_Click()
Dim sPath As String
If Right$(Dir1.Path, 1) = "\" Then
sPath = Dir1.Path & File1.FileName
Else
sPath = Dir1.Path & "\" & File1.FileName
End If
Set Picture1.Picture = LoadPicture(sPath)
End Sub
Private Sub Form_Load()
File1.Pattern = ".bmp;.gif;*.jpg"
End Sub
Private Sub Form_Load()
Form2.Picture1.Picture = Form1.Picture1.Picture
Form2.Text1.Text = Form1.Text1.Text
Form2.Text2.Text = Form1.Text2.Text
Form2.Combo1.Text = Form1.Combo1.Text
Form2.Combo2.Text = Form1.Combo2.Text
Form2.Combo3.Text = Form1.Combo3.Text
End Sub
Option Explicit
Private Sub Command2_Click()
Dim Filter As String
Dim strFileName As String 'String of file to open
Dim strtext As String 'Contents of file
'Dim strFilter As String 'Common Dialog filter string
Dim strBuffer As String 'String buffer variable
Dim FileHandle% 'Variable to hold file handle
On Error GoTo SaveAsError
Filter = "all files (.)|.|"
Filter = Filter + "HTML Files(.htm)|.htm|"
Filter = Filter + "Text Files(.txt)|.txt|"
Filter = Filter + "Batch Files (.bat)|.bat|"
Filter = Filter + "Document Files (.Doc)|.Doc|"
CommonDialog1.Filter = Filter
CommonDialog1.ShowSave
CommonDialog1.FilterIndex = 2
CommonDialog1.Action = 2
If CommonDialog1.FileName <> "" Then
'If it is not blank, open the file
strFileName = CommonDialog1.FileName
strtext = Text1.Text
FileHandle% = FreeFile
Open strFileName For Output As #FileHandle%
MousePointer = vbHourglass
Print #FileHandle%, strtext
MousePointer = vbDefault
Close #FileHandle%
End If
Exit Sub
SaveAsError:
MsgBox "you canceled the dialog box"
Exit Sub
End Sub
Regards,
jfuture.
Hello,Sir
actually i'd made a project regarding my teacher's profile where i've 1-form containing :-
This Form has background color which insert from properties->picture;also
labels,textbox,combo box are all in different color( properties->background).
Now when i save this form in this format which is stated above but when its saved
it is in plain text without picture.
Label Textbox
1)Teachers Name Text1
2)Subjects Text2
3)Email-id Combo-box & one Picture box
This above form also has 2-command buttons ( Saveas,Preview)
I've all the codings for all of this but i want to save my form in as it is format including colors & picture.
Below is the coding:
Private Sub Command1_Click() 'Preview button
Form2.Show
End Sub
Private Sub dir1_change()
File1.Path = Dir1.Path
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub
Private Sub File1_Click()
Dim sPath As String
If Right$(Dir1.Path, 1) = "\" Then
sPath = Dir1.Path & File1.FileName
Else
sPath = Dir1.Path & "\" & File1.FileName
End If
Set Picture1.Picture = LoadPicture(sPath)
End Sub
Private Sub Form_Load()
File1.Pattern = ".bmp;.gif;*.jpg"
End Sub
Private Sub Form_Load()
Form2.Picture1.Picture = Form1.Picture1.Picture
Form2.Text1.Text = Form1.Text1.Text
Form2.Text2.Text = Form1.Text2.Text
Form2.Combo1.Text = Form1.Combo1.Text
Form2.Combo2.Text = Form1.Combo2.Text
Form2.Combo3.Text = Form1.Combo3.Text
End Sub
Option Explicit
Private Sub Command2_Click()
Dim Filter As String
Dim strFileName As String 'String of file to open
Dim strtext As String 'Contents of file
'Dim strFilter As String 'Common Dialog filter string
Dim strBuffer As String 'String buffer variable
Dim FileHandle% 'Variable to hold file handle
On Error GoTo SaveAsError
Filter = "all files (.)|.|"
Filter = Filter + "HTML Files(.htm)|.htm|"
Filter = Filter + "Text Files(.txt)|.txt|"
Filter = Filter + "Batch Files (.bat)|.bat|"
Filter = Filter + "Document Files (.Doc)|.Doc|"
CommonDialog1.Filter = Filter
CommonDialog1.ShowSave
CommonDialog1.FilterIndex = 2
CommonDialog1.Action = 2
If CommonDialog1.FileName <> "" Then
'If it is not blank, open the file
strFileName = CommonDialog1.FileName
strtext = Text1.Text
FileHandle% = FreeFile
Open strFileName For Output As #FileHandle%
MousePointer = vbHourglass
Print #FileHandle%, strtext
MousePointer = vbDefault
Close #FileHandle%
End If
Exit Sub
SaveAsError:
MsgBox "you canceled the dialog box"
Exit Sub
End Sub
My ultimate aim is that to provide User to save my application/form in as it is format
I've developed a project which i want it to be used by user as a software,which enables any user to
download on to their hard-drive whether they have a VB or not.My question is that my application which
i'd made to be saved on drive ( whole form/app. including backgroung color,textbx color....) It's exe.file
o.k now when i write any input or fill the content in my text-box it displays in plain format only &
i don't want this to happen;what i require is my exe.file should be saved as it is as i 've made. For
example you make a software in Vb regarding your personal diet chart withbackground-col, color txt-bx,col-labels,col-combobx
with picture bx,command button......fine then you convert this to exe.file;now if you want to launch
this software how can any user download this with all the details including the above mention list.Only
the thing where i've got stuck is saving my software/application;The important thing after converting
my application to exe.file it's in a same format with all those colors & other properties;but when i
write something in the textbx or combo-bx its displaying in plain format.This is where i need to explore
more & i expect that you'll provide me all the needed code function furthur required.Hope you'll guide
me.
Regards,
jfuture.
This thread is for discussions of Get the Message - MSMQ.