Page 1 of 1

MSMQ - Microsoft Message Queues?

Posted: Thu Mar 15, 2007 5:32 pm
by techjunkie
Have anyone tried to do an application in PB using MSMQ? or do I have to switch to Visual Studio (it's very easy in Visual C++ 2005).

Posted: Sat Aug 11, 2007 1:29 am
by r_hyde
I recently need to write a service that would interact with other services using MSMQ, and using PureDispHelper I managed to make a very basic implementation of it. Here's a simplified example:

(you'll need the PureDispHelper lib, of course)

Code: Select all

#MQ_RECEIVE_ACCESS = 1
#MQ_SEND_ACCESS = 2
#MQ_PEEK_ACCESS = 32
#MQ_DENY_NONE = 0
#MQ_DENY_RECEIVE_SHARE = 1
#MQ_NO_TRANSACTION = 0
#MQ_MTS_TRANSACTION = 1
#MQ_XA_TRANSACTION = 2
#MQ_SINGLE_MESSAGE = 3
#MQ_ERROR_QUEUE_NOT_EXIST = -1072824317
#MQMSG_ACKNOWLEDGMENT_FULL_REACH_QUEUE = 5
#MQMSG_ACKNOWLEDGMENT_FULL_RECEIVE = 14
#DEFAULT_MAX_TIME_TO_REACH_QUEUE = 20

qi = dhCreateObject("MSMQ.MSMQQueueInfo.1")
dhPutValue(qi, "PathName=%s", @".\private$\TestQueue")

;Send a message
dhGetValue("%o", @myq, qi, "Open(%d,%d)", #MQ_SEND_ACCESS, #MQ_DENY_NONE)

If myq
  Debug "Opened private$\TestQueue for sending"
  out_msg = dhCreateObject("MSMQ.MSMQMessage.1")
  body.s = "Hello MSMQ!"
  label.s = "TestMessage"
  dhPutValue(out_msg, "Label=%s", @label)
  dhPutValue(out_msg, "Body=%s", @body)
  Debug "   sending message 'TestMessage' with content='Hello MSMQ!'"
  dhCallMethod(out_msg, "Send(%o)", myq)
  dhReleaseObject(out_msg)
  
  dhCallMethod(myq, "Close()")
  Debug "Queue closed"
  dhReleaseObject(myq)
EndIf

Debug ""

;Receive the message
dhGetValue("%o", @myq, qi, "Open(%d,%d)", #MQ_RECEIVE_ACCESS, #MQ_DENY_NONE)

If myq
  Debug "Opened private$\TestQueue for receiving"
  dhGetValue("%o", @in_msg, myq, "Receive()")
  If msg
    dhGetValue("%s", @message, in_msg, "Body")
    Debug "   Message received: '" + PeekS(message) + "'"
    dhReleaseObject(in_msg)
  EndIf
  dhCallMethod(myq, "Close()")
  Debug "Queue closed"
  dhReleaseObject(myq)
EndIf

dhReleaseObject(qi)
I hope you can find some use for this:)

Posted: Sat Aug 11, 2007 2:52 pm
by techjunkie
Cool! Thanks! :) I will try it later... The specific thing I wanted to do when I wrote the first post, I later did in VBScript though.