Python and MSMQ

I try to create a Python Script who will send a MSMQ message, aknolege the return etc I'm not able to acces the Queue. It's the first time I use MSMQ.

This is a extrac of the script I made. Note that I use a xsl to modified the first xml file I generate.

    def _transmit(self, xml):
        requestMSMQ = win32com.client.Dispatch("MSMQ.MSMQQueueInfo")
       
        requestMSMQ.FormatName = "DIRECT=OS:" + self._connectString
        requestQueue = requestMSMQ.Open(MQ_SEND_ACCESS, MQ_DENY_NONE)
       
        replyMSMQ = win32com.client.Dispatch("MSMQ.MSMQQueueInfo")
        replyMSMQ.FormatName = "DIRECT=OS:" + self._connectString + "_admin"
        ReplyQueue = ReplyQueueInfo.Open(MQ_SEND_ACCESS, MQ_DENY_NONE)
       
        message = win32com.client.Dispatch("MSMQ.MSMQMessage")
        message.Ack = MQMSG_ACKNOWLEDGMENT_FULL_RECEIVE
        message.AdminQueueInfo = replyMSMQ
        message.MaxTimeToReceive = 10
        message.Journal = MQMSG_JOURNAL + MQMSG_DEADLETTER
   
        message.Label = str(self._completed.Format("%Y-%m-%d %H:%M:%S"))
        message.Body = xml
        message.Delivery = MQMSG_DELIVERY_RECOVERABLE  
        message.Send(requestQueue)
       
        replyMessage = ReplyQueue.Receive(ReceiveTimeout=10000)

        RequestQueue.Close()
        ReplyQueue.Close()
        ReplyMSMQ.Delete()

        if ReplyMessage is None:
            self._raise("Failed to receive transmission confirmation.")
       
def main():

    MSMQDistributor()()


Thank for your help
DwezillAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ramromconsultant Commented:
I think no one has responded because the question is specific to MSMQ, which probably none of us are familiar with. Also we don't have a clear picture of what "I'm not able to acces the Queue" means and where/how the problem is being detected. It is IMHO not really a Python question.

Perhaps you should also try in the appropriate Windows Server Topic Area.

Please tell us what "I'm not able to acces the Queue" means and where/how the problem is being detected/reported.

Bob Gailer Page Editor.
0
ramromconsultant Commented:
I just installed MSMQ and am prepared to test your code on my computer (Win 2000 Server). Since I am new to MSMQ I need to know what self._connectString looks like, and what else if anything I must do to configure/enable/administer MSMQ.

I have gotten past - requestMSMQ = win32com.client.Dispatch("MSMQ.MSMQQueueInfo") - and need some help.
0
DwezillAuthor Commented:
I have foud a solution to my problem, it have to do with the moment I create the differente object MSMQ i need.
it's look like it's dont work if it's in " late bending", you have to be shure you are woorkink in a early bending mode.

The Gen_Py file for the MSMQ should be generate with this :
"Python22\Lib\site-packages\win32com\client\makepy.py"

The correct code look like that:

from xml.dom import minidom
import win32com.client

# Constants declaration
MQ_RECEIVE_ACCESS = 1
MQ_SEND_ACCESS = 2
MQ_DENY_NONE = 0

MQMSG_ACKNOWLEDGMENT_FULL_RECEIVE  = 14
MQMSG_DELIVERY_RECOVERABLE = 1
MQMSG_JOURNAL =2
MQMSG_DEADLETTER=1
 
MQMSG_CLASS_NACK_REACH_QUEUE_TIMEOUT = 32770
MQMSG_CLASS_ACK_RECEIVE = 16384
MQMSG_CLASS_NACK_RECEIVE_TIMEOUT = 49154

Here go the code who genrate the xml file I whant to transmit

   def _transmit(self, xml):
        requestMSMQ = win32com.client.Dispatch("MSMQ.MSMQQueueInfo")
       
        requestMSMQ.FormatName = "DIRECT=OS:" + self._connectString
        requestQueue = requestMSMQ.Open(MQ_SEND_ACCESS, MQ_DENY_NONE)
       
        replyMSMQ = win32com.client.Dispatch("MSMQ.MSMQQueueInfo")
        replyMSMQ.FormatName = "DIRECT=OS:" + self._connectString + "_admin"
        replyQueue = replyMSMQ.Open(MQ_SEND_ACCESS, MQ_DENY_NONE)
       
        message = win32com.client.Dispatch("MSMQ.MSMQMessage")
        message.Ack = MQMSG_ACKNOWLEDGMENT_FULL_RECEIVE
        message.AdminQueueInfo = replyMSMQ
        message.MaxTimeToReceive = 5
        message.Journal = MQMSG_JOURNAL + MQMSG_DEADLETTER
   
        message.Label = str(self._completed.Format("%Y-%m-%d %H:%M:%S"))
        message.Body = xml
        message.Delivery = MQMSG_DELIVERY_RECOVERABLE  
        message.Send(requestQueue)

        requestQueue.Close()
        replyQueue.Close()

        self._logText("Waiting confirmation...")
       
        replyQueue = replyMSMQ.Open(MQ_RECEIVE_ACCESS , MQ_DENY_NONE)
        replyMessage = replyQueue.Receive(ReceiveTimeout=10000)

        if message.Id!=replyMessage.CorrelationId:self._raise("Transmission failed.")
        requestQueue.Close()
        replyQueue.Close()
#        replyMSMQ.Delete()

        if replyMessage is None:
            self._raise("Failed to receive transmission confirmation.")
       
def main():

    MSMQDistributor()()
0
WesLennonCommented:
Question has been answered by the Author and the answer is ID# 12617348

Question will go into PAQ and points refunded.

Thanks,

Wes Lennon
DoCS
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Python

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.