I'm trying to convert Microsoft's Visual Basic / C++ example code to Python 3. It sends a MSMQ Message which requests a response in a response queue.
The example is here: https://msdn.microsoft.com/en-us/library/ms705720(v=vs.85).aspx
import win32com.client
import os
computer_name = os.getenv('COMPUTERNAME')
strdestformatname = "direct=os:" + computer_name + "\\PRIVATE$\\python_in"
strrespformatname = "direct=os:" + computer_name + "\\PRIVATE$\\python_out"
dest_msmq = win32com.client.Dispatch("MSMQ.MSMQDestination")
resp_msmq = win32com.client.Dispatch("MSMQ.MSMQDestination")
dest_msmq.FormatName = strdestformatname
resp_msmq.FormatName = strdestformatname
msg = win32com.client.Dispatch("MSMQ.MSMQMessage")
# This next line creates
# Member not found
# pywintypes.com_error: (-2147352573, 'Mitglied nicht gefunden.', None, None)
msg.ResponseDestination = resp_msmq
msg.Label = "Test Message: Response"
msg.Send(DestinationQueue = dest_msmq)
I have created a "python_in" and "python_out" MSMQ queue on my computer. These work. If I remove the line:
msg.ResponseDestination = resp_msmq
the message appears in the "python_in" queue. I cand also send it directly to the "python_out" queue.
The error message is
pywintypes.com_error: (-2147352573, 'Mitglied nicht gefunden.', None, None (=Member not found)
Below is an image showing how the message arrives when commenting out the reply queue code. Without a reply queue, of course.
Some additional info: I'm testing this on Win7 professional with 32bit Python 3.6.5 and the latest pywin32 (version 223) installed.
Info on how to do MSMQ without reply is here: http://gouthamanbalaraman.com/blog/sending-msmq-messages-python.html
Someone claims he got a similar thing to work (setting a response for acknowledgement), here, with source: https://www.experts-exchange.com/questions/21207798/Python-and-MSMQ.html
I also got this to run in IronPython a few years ago, but that one is Python 2 How to create a new MSMQ message in IronPython with label, reply queue and other properties