• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2939
  • Last Modified:

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
0
Dwezill
Asked:
Dwezill
  • 2
1 Solution
 
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now