Results 1 to 5 of 5

Thread: MQSeries

  1. #1

    Thread Starter
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    Post

    I am trying to get two PCs talk to each other using MQSeries.

    With little sucess

    The trouble is, I can't determine weather the fault is on the server or client side.

    Has anybody got a set of scripts to setup queues and a sample VB interface as a starting point?



    ------------------
    Mark Sreeves
    Analyst Programmer

    [email protected]
    A BMW Group Company

  2. #2
    Hyperactive Member compuGEEK's Avatar
    Join Date
    May 1999
    Location
    Mpls,MN,USA
    Posts
    281

    Post

    Are you trying it with NT?



    ------------------
    CompuGEEK
    [email protected]



  3. #3

    Thread Starter
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    Post

    YES!

    ------------------
    Mark Sreeves
    Analyst Programmer

    [email protected]
    A BMW Group Company

  4. #4
    Hyperactive Member compuGEEK's Avatar
    Join Date
    May 1999
    Location
    Mpls,MN,USA
    Posts
    281

    Post

    I've been playing with this a bit myself and came across this on MSDN. I have yet to dig in and start coding.

    I hope this help you out:

    Cursors and Asynchronous Messaging

    Things get a bit more complicated when cursors are used in conjunction with asynchronous messaging. Say you'd like to implement an asynchronous version of the preceding message enumeration. Let's take a look at a code fragment in Visual Basic and analyze its various elements.

    This sample simply asynchronously peeks at or receives the next message in the queue. Use AsyncPeek to asynchronously peek at each message as it arrives, and AsyncReceive to asynchronously receive.

    Dim qinfo As MSMQQueueInfo
    Dim qRec as MSMQQueue
    Dim WithEvents qeventPeek As MSMQEvent
    Dim WithEvents qeventReceive As MSMQEvent
    Sub AsyncReceive
    Set qRec = qinfo.Open(MQ_PEEK_ACCESS, MQ_DENY_NONE)
    Set qeventReceive = New MSMQEvent
    qRec.EnableNotification qevent, Cursor:=MQMSG_CURRENT
    End Sub
    Sub AsyncPeek
    Set qRec = qinfo.Open(MQ_PEEK_ACCESS, MQ_DENY_NONE)
    Set qeventPeek = New MSMQEvent
    qRec.EnableNotification qevent, Cursor:=MQMSG_CURRENT
    End Sub
    Private Sub qeventPeek_Arrived(ByVal Queue As Object, ByVal Cursor As Long)
    Dim m As MSMQMessage
    Set m = Queue.PeekCurrent
    MsgBox m.Label
    qRec.EnableNotification qevent, Cursor:=MQMSG_NEXT
    End Sub
    Private Sub qeventReceive_Arrived(ByVal Queue As Object, ByVal Cursor As Long)
    Dim m As MSMQMessage
    Set m = Queue.ReceiveCurrent
    MsgBox m.Label
    qRec.EnableNotification qevent, Cursor:=MQMSG_CURRENT
    End Sub

    You will note that there are three cursor-related elements in the canonic structure of this sample:

    Which cursor parameter is specified to the initial EnableNotification call in AsyncPeek/AsyncReceive. This can be either MQMSG_CURRENT or MQMSG_NEXT. When using the implicit cursor, MQMSG_FIRST should never be used.


    Which Peek/Receive method is invoked. Can be one of ReceiveCurrent, PeekCurrent, or PeekNext.


    Which cursor parameter is specified to EnableNotification within the handler to reenable notifications.
    So we see that there are 2 * 3 * 2 = 12 different combinations—not all of which necessarily make sense. Try out some of the other variants and see what effect they have on your enumeration.

    Cursors and Priorities
    Here are a couple of samples that show something important about how cursors work with priority queues—there's nothing Visual Basic-centric per se about them. The same samples could be written in C.

    The main point that is demonstrated in these samples is that a cursor will be repositioned by MSMQ to reference a newly arrived message if that message arrives while your application is actually waiting for a message.

    Dim qinfo As New MSMQQueueInfo
    Dim qSend As MSMQQueue
    Dim qReceive As MSMQQueue
    Sub TestCursor()
    qinfo.PathName = ".\q" & Now
    qinfo.Create
    Set qSend = qinfo.Open(MQ_SEND_ACCESS, 0)

    Dim m As New MSMQMessage
    For i = 1 To 10
    m.Body = i
    m.Priority = Int(Rnd * 3) + 1
    m.Send qSend
    Next
    '
    ' peek to end of queue
    '
    Dim m2 As MSMQMessage
    Set qReceive = qinfo.Open(MQ_RECEIVE_ACCESS, 0)
    Set m2 = qReceive.PeekCurrent(ReceiveTimeout:=10)
    While Not m2 Is Nothing
    Set m2 = qReceive.PeekNext(ReceiveTimeout:=10)
    Wend
    '
    ' send a hipri msg
    '
    m.Body = "hi pri"
    m.Priority = 4
    m.Send qSend ' will be appended to front of queue
    m.Body = "lo pri" ' send a lopri msg
    m.Priority = 0
    m.Send qSend ' will be appended to tail of queue
    '
    ' returns the lo-pri message: need PeekCurrent,
    ' not PeekNext since previous PeekNext failed.
    '
    Set m2 = qReceive.PeekCurrent(ReceiveTimeout:=10)
    msgbox m2.body
    End Sub

    Note this sample returns the lo-pri message at the tail of the queue because the cursor is still positioned at the end of queue when the Peek call is made.

    Contrast this with the next example:

    Dim qinfo As New MSMQQueueInfo
    Dim qSend As MSMQQueue
    Dim qReceive As MSMQQueue
    Dim WithEvents qevent As MSMQEvent
    Private Sub TestCursor2()
    qinfo.PathName = ".\q" & Now
    qinfo.Create
    Set qSend = qinfo.Open(MQ_SEND_ACCESS, 0)

    Dim m As New MSMQMessage
    For i = 1 To 10
    m.Body = i
    m.Priority = Int(Rnd * 3) + 1
    m.Send qSend
    Next
    '
    ' peek to end of queue
    '
    Dim m2 As MSMQMessage
    Set qReceive = qinfo.Open(MQ_RECEIVE_ACCESS, 0)
    Set m2 = qReceive.PeekCurrent(ReceiveTimeout:=10)
    While Not m2 Is Nothing
    Set m2 = qReceive.PeekNext(ReceiveTimeout:=10)
    Wend
    '
    ' setup async handler
    '
    Set qevent = New MSMQEvent
    qReceive.EnableNotification qevent, MQMSG_CURRENT, 10000
    '
    ' send a hipri msg
    '
    m.Body = "hi pri"
    m.Priority = 4
    m.Send qSend ' will be appended to front of queue
    '
    ' send a lopri msg
    '
    m.Body = "lo pri"
    m.Priority = 0
    m.Send qSend ' will be appended to tail of queue
    End Sub
    Private Sub qevent_Arrived(ByVal Queue As Object, ByVal Cursor As Long)
    Dim qReceive As MSMQQueue
    '
    ' get next msg
    '
    Set qReceive = Queue
    Dim m2 As MSMQMessage
    Set m2 = qReceive.PeekCurrent(ReceiveTimeout:=10) ' returns hi-pri msg

    msgbox m2.Body
    End Sub

    In this case, the high-priority message from the head of the queue is returned. Why? Because it arrived at the head of the queue while the cursor was positioned at the queue tail still waiting for a message to show up there. So, effectively the cursor was repositioned to the newly arrived message.

    This is a nice feature—it basically allows you to write cursor-based asynchronous message handlers that never miss newly arrived messages


    ------------------
    CompuGEEK
    [email protected]



  5. #5

    Thread Starter
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    Post

    CompuGEEK, Thanks for all that but (there's always a but isn't there!)

    I think I've got ist sussed now and...

    The information you've posted relates to MSMQ which is Microsoft's Imitation of IBM's MQSeries.

    I do still have one or two MQSeries questions though. I'll try and seek out an MQSeries forum.

    Thanks once again for your help.




    ------------------
    Mark Sreeves
    Analyst Programmer

    [email protected]
    A BMW Group Company

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width