Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming A Distributed Message Queue Application Raphi Renous Software Development Engineer Desktop And Business Systems Division Microsoft Corporation.

Similar presentations


Presentation on theme: "Programming A Distributed Message Queue Application Raphi Renous Software Development Engineer Desktop And Business Systems Division Microsoft Corporation."— Presentation transcript:

1 Programming A Distributed Message Queue Application Raphi Renous Software Development Engineer Desktop And Business Systems Division Microsoft Corporation

2 Agenda Falcon (MSMQ) features Falcon (MSMQ) features Distributed whiteboard demo Distributed whiteboard demo C/C++ API C/C++ API ActiveX Components ActiveX Components Summary Summary Questions? Questions?

3 Falcon (MSMQ) Features Sessionless with asynchronous send and receive Sessionless with asynchronous send and receive Protocol and platform-independent API Protocol and platform-independent API Scalable to large number of nodes Scalable to large number of nodes Robust: reliable, guaranteed, transactional Robust: reliable, guaranteed, transactional Integrated security Integrated security System-wide priority policy System-wide priority policy Advanced logging and tracking Advanced logging and tracking Multireader, multisender, multithreaded Multireader, multisender, multithreaded Support for legacy systems Support for legacy systems SDK: C/C++ API, ActiveX Components SDK: C/C++ API, ActiveX Components

4 Demo Distributed whiteboard

5 C/C++ API Function sets Function sets Queue manipulation Queue manipulation Queue location Queue location Message manipulation Message manipulation Utilities Utilities Message and queue objects represented using properties Message and queue objects represented using properties Use MQ.H, MQRT.LIB Use MQ.H, MQRT.LIB

6 Properties Properties associated with queues and messages Properties associated with queues and messages Each property consists of ID, type, value Each property consists of ID, type, value Property set Property set Count Count Array of IDs Array of IDs Array of variants (tagged union) containing type and value Array of variants (tagged union) containing type and value Array of status codes (optional) Array of status codes (optional) ID names: PROPID_Q_* or PROPID_M_* ID names: PROPID_Q_* or PROPID_M_*

7 Usage Overview Queue creation Queue creation Form queue property set Form queue property set Call MQCreateQueue() with property set Call MQCreateQueue() with property set Queue opening Queue opening Obtain queue format name Obtain queue format name By creating the queue By creating the queue From the queue location function From the queue location function Set by the application Set by the application Call MQOpenQueue() with format name Call MQOpenQueue() with format name

8 Usage Overview Message reception Message reception Open queue for receive access Open queue for receive access Determine message property set to be received Determine message property set to be received Call MQReceiveMessage() with open queue handle and property set Call MQReceiveMessage() with open queue handle and property set If asynchronous, write code to handle message arrival If asynchronous, write code to handle message arrival Message sending Message sending Open queue for send access Open queue for send access Form message property set Form message property set Call MQSendMessage() with open queue handle and property set Call MQSendMessage() with open queue handle and property set

9 Queue Manipulation Default security: get properties/permissions and send Default security: get properties/permissions and send Queue properties Queue properties PATHNAME, LABEL, SERVICETYPE, INSTANCE, TRANSACTIONAL, BASEPRIORITY, AUTHENTICATE, JOURNAL, PRIV_LEVEL, QUOTA PATHNAME, LABEL, SERVICETYPE, INSTANCE, TRANSACTIONAL, BASEPRIORITY, AUTHENTICATE, JOURNAL, PRIV_LEVEL, QUOTA PATHNAME property specifies public/private queue PATHNAME property specifies public/private queue Public Public Stored in MSMQ Information Service database Stored in MSMQ Information Service database MachineName\QueueName MachineName\QueueName Private Private Stored on disk of local machine Stored on disk of local machine MachineName\Private$\QueueName MachineName\Private$\QueueName HRESULT MQCreateQueue(IN PSECURITY_DESCRIPTOR pSecurityDesc, IN OUT MQQUEUEPROPS *pQueueProps, IN OUT MQQUEUEPROPS *pQueueProps, OUT LPWSTR lpwcsFormatName, OUT LPWSTR lpwcsFormatName, IN OUT LPDWORD lpdwFormatNameLength) IN OUT LPDWORD lpdwFormatNameLength) HRESULT MQDeleteQueue(IN LPWSTR lpwcsFormatName)

10 Format name Format name Specifies how to get to a queue Specifies how to get to a queue Public=QueueInstance Public=QueueInstance Private=MachineGUID\QueueInstance Private=MachineGUID\QueueInstance Direct=Protocol:MachineAddress\ QueueName Direct=OS:MachineAddress\QueueName Direct=Protocol:MachineAddress\ QueueName Direct=OS:MachineAddress\QueueName Not a property Not a property Returned by MQCreateQueue() Returned by MQCreateQueue() Obtained from the properties returned by the queue location functions Obtained from the properties returned by the queue location functions Formed by the application Formed by the application Queue Manipulation

11 Subject to queue security Subject to queue security One type of access per queue handle One type of access per queue handle MQ_SEND_ACCESS, MQ_RECEIVE_ACCESS, MQ_PEEK_ACCESS MQ_SEND_ACCESS, MQ_RECEIVE_ACCESS, MQ_PEEK_ACCESS Share mode Share mode 0 - available to everyone (must be used for peek and send) 0 - available to everyone (must be used for peek and send) MQ_DENY_RECEIVE_SHARE - only this process can receive MQ_DENY_RECEIVE_SHARE - only this process can receive HRESULT MQOpenQueue(IN LPWSTR lpwcsFormatName, IN DWORD dwAccess, IN DWORD dwAccess, IN DWORD dwShareMode, IN DWORD dwShareMode, OUT LPQUEUEHANDLE phQueue) OUT LPQUEUEHANDLE phQueue) HRESULT MQCloseQueue(IN QUEUEHANDLE hQueue) Queue Manipulation

12 QUEUEPROPID aPropId[1]; MQPROPVARIANT aPropVar[1]; DWORD cProps = 0; aPropId[cProps] = PROPID_Q_PATHNAME; aPropVar[cProps].vt= VT_LPWSTR; aPropVar[cProps].pwszVal = Lmachine\\queue; cProps++; MQQUEUEPROPS propsQueue; propsQueue.cProps = cProps; propsQueue.aPropId = aPropId; propsQueue.aPropVar = aPropVar; propsQueue.aStatus = NULL; WCHAR szFormat[MAX_FORMAT_NAME_LEN]; DWORD dwSize = MAX_FORMAT_NAME_LEN; HRESULT hr = MQCreateQueue(NULL, &propsQueue, szFormat, &dwSize); QUEUEHANDLE hQueue; if (!FAILED(hr)) hr = MQOpenQueue(szFormat, MQ_RECEIVE_ACCESS, 0, &hQueue); hr = MQOpenQueue(szFormat, MQ_RECEIVE_ACCESS, 0, &hQueue); Queue Manipulation

13 Queue Location Powerful - do not need to know exact location of queue Powerful - do not need to know exact location of queue Context - starting point in name space (currently NULL ) Context - starting point in name space (currently NULL ) Restriction set Restriction set Property information (ID, type, value) Property information (ID, type, value) Comparison operation for each property Comparison operation for each property Column set - queue properties to be returned by query Column set - queue properties to be returned by query Sort set - sort order for results (optional) Sort set - sort order for results (optional) Property IDs from column set Property IDs from column set Order for each property ID Order for each property ID Returns enumeration handle (does not retrieve results) Returns enumeration handle (does not retrieve results) HRESULT MQLocateBegin(IN LPCWSTR lpwcsContext, IN MQRESTRICTION *pRestriction, IN MQRESTRICTION *pRestriction, IN MQCOLUMNSET *pColumns, IN MQCOLUMNSET *pColumns, IN MQSORTSET *pSort, IN MQSORTSET *pSort, OUT PHANDLE phEnum) OUT PHANDLE phEnum)

14 Call MQLocateNext() until (*pcProps) on output < (*pcProps) on input Call MQLocateNext() until (*pcProps) on output < (*pcProps) on input Returns as many complete results as possible Returns as many complete results as possible Must free memory allocated by Falcon (if any) using MQFreeMemory() Must free memory allocated by Falcon (if any) using MQFreeMemory() HRESULT MQLocateNext(IN HANDLE hEnum, IN OUT DWORD *pcProps, IN OUT DWORD *pcProps, OUT PROPVARIANT aPropVar[]) OUT PROPVARIANT aPropVar[]) HRESULT MQLocateEnd(IN HANDLE hEnum) Queue Location

15 MQPROPERTYRESTRICTION aPropRestriction[1]; DWORD cProps = 0; aPropRestriction[cProps].rel = PREQ; aPropRestriction[cProps].prop = PROPID_Q_LABEL; aPropRestriction[cProps].prval.vt = VT_LPWSTR; aPropRestriction[cProps].prval.pwszVal= Llabel; cProps++; MQRESTRICTION Restriction; Restriction.cRes = cProps; Restriction.paPropRes = aPropRestriction; QUEUEPROPID aPropId[1]; cProps = 0; aPropId[cProps] = PROPID_Q_INSTANCE; cProps++; MQCOLUMNSET Column; Column.cCol = cProps; Column.aCol = aPropId; Queue Location

16 DWORD hEnum; HRESULT hr = MQLocateBegin(NULL, &Restriction, &Column, NULL, &hEnum); NULL, &hEnum); if (!FAILED(hr)) { MQPROPVARIANT aPropVar[1]; MQPROPVARIANT aPropVar[1]; DWORD cQueue = 1; DWORD cQueue = 1; hr = MQLocateNext(hEnum, &cQueue, &Column, aPropVar); hr = MQLocateNext(hEnum, &cQueue, &Column, aPropVar); if (!FAILED(hr) && cQueue > 0) if (!FAILED(hr) && cQueue > 0) { WCHAR szFormat[MAX_FORMAT_NAME_LEN]; WCHAR szFormat[MAX_FORMAT_NAME_LEN]; DWORD dwSize = MAX_FORMAT_NAME_LEN; DWORD dwSize = MAX_FORMAT_NAME_LEN; hr = MQGuidToFormatName(aPropVar[0].puuid, hr = MQGuidToFormatName(aPropVar[0].puuid, szFormat, &dwSize); szFormat, &dwSize); if (!FAILED(hr)) if (!FAILED(hr))... /* Open queue */... /* Open queue */ MQFreeMemory(apropVar[0].puuid); MQFreeMemory(apropVar[0].puuid); } MQLocateEnd(hEnum); MQLocateEnd(hEnum);} Queue Location

17 Message Manipulation Message properties Message properties BODY, LABEL, DELIVERY, PRIORITY, TIME_TO_BE_RECEIVED, TIME_TO_REACH_QUEUE, JOURNAL, ACKNOWLEDGE, CORRELATIONID, APPSPECIFIC, ADMIN_QUEUE, RESPONSE_QUEUE, PRIVACYLEVEL, SECURITY_CONTEXT BODY, LABEL, DELIVERY, PRIORITY, TIME_TO_BE_RECEIVED, TIME_TO_REACH_QUEUE, JOURNAL, ACKNOWLEDGE, CORRELATIONID, APPSPECIFIC, ADMIN_QUEUE, RESPONSE_QUEUE, PRIVACYLEVEL, SECURITY_CONTEXT Always asynchronous Always asynchronous Use TIME_TO_BE_RECEIVED or TIME_TO_REACH_QUEUE property to specify time limit for message to reach destination Use TIME_TO_BE_RECEIVED or TIME_TO_REACH_QUEUE property to specify time limit for message to reach destination Transaction interface Transaction interface Get from MS ® DTC Get from MS ® DTC HRESULT MQSendMessage(IN QUEUEHANDLE hDestinationQueue, IN MQMSGPROPS * pMessageProps, IN MQMSGPROPS * pMessageProps, IN ITransaction * pTransaction) IN ITransaction * pTransaction)

18 Action Action MQ_ACTION_RECEIVE, MQ_ACTION_PEEK_CURRENT, MQ_ACTION_PEEK_NEXT MQ_ACTION_RECEIVE, MQ_ACTION_PEEK_CURRENT, MQ_ACTION_PEEK_NEXT Additional message properties Additional message properties CLASS, MSGID, SENDERID, SRC_MACHINE, SENDER_CERTIFICATE CLASS, MSGID, SENDERID, SRC_MACHINE, SENDER_CERTIFICATE Allows asynchronous receive Allows asynchronous receive Callback function, Win32 ® event, Windows NT ® completion port Callback function, Win32 ® event, Windows NT ® completion port Cursor used to traverse messages in queue Cursor used to traverse messages in queue Transaction interface Transaction interface Get from MS DTC Get from MS DTC HRESULT MQReceiveMessage(IN QUEUEHANDLE hSourceQueue, IN DWORD dwTimeOut, IN DWORD dwTimeOut, IN DWORD dwAction, IN DWORD dwAction, IN OUT MQMSGPROPS *pMessageProps, IN OUT MQMSGPROPS *pMessageProps, IN OUT LPOVERLAPPED lpOverlapped, IN OUT LPOVERLAPPED lpOverlapped, IN PMQRECEIVECALLBACK fnReceiveCallback, IN PMQRECEIVECALLBACK fnReceiveCallback, IN HANDLE hCursor, IN HANDLE hCursor, IN ITransaction * pTransaction) IN ITransaction * pTransaction) Message Manipulation

19 MSGPROPID aPropId[1]; MQPROPVARIANT aPropVar[1]; DWORD cProps = 0; WCHAR szBody[MAX_MSG_BODY_LEN]; aPropId[cProps] = PROPID_M_BODY; aPropVar[cProps].vt= VT_UI1 | VT_VECTOR; aPropVar[cProps].cab.cElems = sizeof(szBody); aPropVar[cProps].cab.pElems = (UCHAR *)szBody; cProps++; MQMSGPROPS propsMsg; propsMsg.cProps = cProps; propsMsg.aPropId = aPropId; propsMsg.aPropVar = aPropVar; propsMsg.aStatus = NULL; HRESULT hr = MQReceiveMessage(hQueue, INFINITE, MQ_ACTION_RECEIVE, &propsMsg, NULL, NULL, NULL, NULL); Message Manipulation

20 Other Functions Queue manipulation Queue manipulation MQGetQueueProperties(), MQSetQueueProperties() MQGetQueueProperties(), MQSetQueueProperties() MQGetQueueSecurity(), MQSetQueueSecurity() MQGetQueueSecurity(), MQSetQueueSecurity() Message manipulation Message manipulation MQCreateCursor(), MQCloseCursor() MQCreateCursor(), MQCloseCursor() Utilities Utilities MQFreeMemory() MQFreeMemory() MQGetMachineProperties() MQGetMachineProperties() MQGuidToFormatName(), MQHandleToFormatName(), MQPathNameToFormatName() MQGuidToFormatName(), MQHandleToFormatName(), MQPathNameToFormatName()

21 ActiveX Components Provide simple end-user programming model without compromising performance Provide simple end-user programming model without compromising performance Support early (vtable) and late ( IDispatch ) binding Support early (vtable) and late ( IDispatch ) binding Direct support for most Falcon functionality within the object model Direct support for most Falcon functionality within the object model No UI required No UI required Usable by any ActiveX Server controller, for example, Usable by any ActiveX Server controller, for example, Visual Basic ® 3.0, Visual Basic 4.0, Visual Basic 5.0 Visual Basic ® 3.0, Visual Basic 4.0, Visual Basic 5.0 Denali Denali Microsoft ® Access Microsoft ® Access Office 97 Office 97 Delphi, PowerBuilder Delphi, PowerBuilder

22 Component Model MSMQQueueInfo : queue object MSMQQueueInfo : queue object MSMQQueue : instance of open queue MSMQQueue : instance of open queue MSMQMessage : message object MSMQMessage : message object MSMQQuery : supports queue location MSMQQuery : supports queue location MSMQQueueInfos : collection of queues MSMQQueueInfos : collection of queues MSMQEvent : asynchronous message arrival notification MSMQEvent : asynchronous message arrival notification Deliverable: mqoa.dll Deliverable: mqoa.dll Contains both implementation and type library Contains both implementation and type library

23 Usage Overview Queue creation Queue creation Set properties in MSMQQueueInfo Set properties in MSMQQueueInfo Call MSMQQueueInfo.Create Call MSMQQueueInfo.Create Queue opening Queue opening Obtain MSMQQueueInfo Obtain MSMQQueueInfo By creating the queue By creating the queue From MSMQQueueInfos returned by MSMQQuery From MSMQQueueInfos returned by MSMQQuery Set q = queueinfo.Open Set q = queueinfo.Open

24 Usage Overview Message reception Message reception mqQueue = queue opened with receive access mqQueue = queue opened with receive access If asynchronous If asynchronous Create MSMQEvent object: set qevent = new MSMQEvent Create MSMQEvent object: set qevent = new MSMQEvent Call mqQueue.EnableNotification(qevent) Call mqQueue.EnableNotification(qevent) Write qevent_Arrived event handler Write qevent_Arrived event handler Set mqMessage = mqQueue.Receive Set mqMessage = mqQueue.Receive Message sending Message sending mqQueue = queue opened with send access mqQueue = queue opened with send access Set properties in mqMessage instance Set properties in mqMessage instance Call mqMessage.Send(mqQueue) Call mqMessage.Send(mqQueue)

25 MSMQQueueInfo Describes a queue object Describes a queue object Methods Methods Create, Delete Create, Delete Open(access, sharemode) as MSMQQueue Open(access, sharemode) as MSMQQueue access: MQMSG_RECEIVE_ACCESS, MQMSG_SEND_ACCESS, MQMSG_PEEK_ACCESS access: MQMSG_RECEIVE_ACCESS, MQMSG_SEND_ACCESS, MQMSG_PEEK_ACCESS sharemode: MQ_DENY_NONE, MQ_DENY_RECEIVE_SHARE sharemode: MQ_DENY_NONE, MQ_DENY_RECEIVE_SHARE Properties Properties strLabel, strPathname, guidServiceType, guidQueue, strFormatName strLabel, strPathname, guidServiceType, guidQueue, strFormatName Example Create queue for my instance Dim qrec As New MSMQQueueInfo qinfo.strPathName = "machine\queue" qinfo.strLabel = "My Draw Queue" qinfo.Create Example Create queue for my instance Dim qrec As New MSMQQueueInfo qinfo.strPathName = "machine\queue" qinfo.strLabel = "My Draw Queue" qinfo.Create

26 MSMQQueue Describes an open queue instance Describes an open queue instance A queue can be concurrently open multiple times A queue can be concurrently open multiple times One-to-many mapping from MSMQQueueInfo to MSMQQueue One-to-many mapping from MSMQQueueInfo to MSMQQueue Analogy: MSMQQueueInfo is to MSMQQueue as File is to FileHandle Analogy: MSMQQueueInfo is to MSMQQueue as File is to FileHandle Provides asynchronous message handling Provides asynchronous message handling Manages collection of messages Manages collection of messages

27 MSMQQueue Methods Methods IsOpen() as Boolean IsOpen() as Boolean Close Close Receive() as MSMQMessage Receive() as MSMQMessage Synchronous message reception Synchronous message reception Peek() as MSMQMessage Peek() as MSMQMessage Synchronous message peeking Synchronous message peeking EnableNotification(qevent as MSMQEvent) EnableNotification(qevent as MSMQEvent) Turns on asynchronous message notification Turns on asynchronous message notification Message arrival to queue will now fire qevent_ Arrived event Message arrival to queue will now fire qevent_ Arrived event DisableNotification DisableNotification Reset Reset Resets message collection to start Resets message collection to start ReceiveNext() / PeekNext() as MSMQMessage ReceiveNext() / PeekNext() as MSMQMessage Cursor based synchronous reception/peek Cursor based synchronous reception/peek

28 MSMQQueue Properties Properties lReceiveTimeout, lAccess, lShareMode, queueinfo, lHandle lReceiveTimeout, lAccess, lShareMode, queueinfo, lHandle Error event fired if timeout expires while synchronously waiting to receive message Error event fired if timeout expires while synchronously waiting to receive message Example Create and open a queue for synchronous reception Dim qinfo As New MSMQQueueInfo Dim myQ As MSMQQueue qinfo.strPathName = "machine\queue" qinfo.Create Set myQ = qinfo.Open(MQMSG_RECEIVE_ACCESS, MQ_DENY_NONE) Example Create and open a queue for synchronous reception Dim qinfo As New MSMQQueueInfo Dim myQ As MSMQQueue qinfo.strPathName = "machine\queue" qinfo.Create Set myQ = qinfo.Open(MQMSG_RECEIVE_ACCESS, MQ_DENY_NONE)

29 MSMQEvent Allows user to write single generic event handler to manage message arrival notification of multiple queues Allows user to write single generic event handler to manage message arrival notification of multiple queues Events Events Arrived(byval pdispQueue as Object) Arrived(byval pdispQueue as Object) Fired when a new message arrives at queue Fired when a new message arrives at queue ArrivedError(byval pdispQueue as Object, byval error as Long) ArrivedError(byval pdispQueue as Object, byval error as Long) Fired to indicate message error in reception Fired to indicate message error in reception

30 MSMQQuery Provides filtered queue location Provides filtered queue location Returns collection of queue objects Returns collection of queue objects Method Method LookupQueue( ) as MSMQQueueInfos LookupQueue( ) as MSMQQueueInfos Example Locate the friend queue Dim queryFriend As New MqQuery Dim qinfosResult As MSMQQueueInfos Set qinfosResult = queryFriend.LookupQueue( strLabel := FriendName, strGuidServiceType := DrawType) Example Locate the friend queue Dim queryFriend As New MqQuery Dim qinfosResult As MSMQQueueInfos Set qinfosResult = queryFriend.LookupQueue( strLabel := FriendName, strGuidServiceType := DrawType)

31 MSMQQueueInfos Manages collection of MSMQQueueInfo objects produced by MSMQQuery Manages collection of MSMQQueueInfo objects produced by MSMQQuery Methods Methods Reset Reset Next() as MSMQQueueInfo Next() as MSMQQueueInfo Example Display the queue label for all the queues Dim queryAll As New MSMQQuery Dim qinfos As MSMQQueueInfos Dim qinfoCurrent As MSMQQueueInfo Set qinfos = queryAll.LookupQueue qinfos.Reset Set qinfoCurrent = qinfos.Next While Not qinfoCurrent Is Nothing MsgBox qinfoCurrent.strLabel Set qinfoCurrent = qinfos.Next Wend Example Display the queue label for all the queues Dim queryAll As New MSMQQuery Dim qinfos As MSMQQueueInfos Dim qinfoCurrent As MSMQQueueInfo Set qinfos = queryAll.LookupQueue qinfos.Reset Set qinfoCurrent = qinfos.Next While Not qinfoCurrent Is Nothing MsgBox qinfoCurrent.strLabel Set qinfoCurrent = qinfos.Next Wend

32 MSMQMessage Describes a message Describes a message Method Method Send(q as MSMQQueue) Send(q as MSMQQueue) Properties Properties body, strLabel, delivery, lPriority, lTimeToBeReceived, lTimeToReachQueue, class, id, idCorrelation, lJournal, acknowledge, queueinfoResponse, queueinfoAdmin, queueinfoDest, lAppSpecific body, strLabel, delivery, lPriority, lTimeToBeReceived, lTimeToReachQueue, class, id, idCorrelation, lJournal, acknowledge, queueinfoResponse, queueinfoAdmin, queueinfoDest, lAppSpecific Example Send the keystroke to the friend Dim OutMsg as New MSMQMessage OutMsg.lPriority = 4 OutMsg.strBody = Chr(KeyAscii) OutMsg.strLabel = "Key: " + OutMsg.strBody OutMsg.Send FriendQ Example Send the keystroke to the friend Dim OutMsg as New MSMQMessage OutMsg.lPriority = 4 OutMsg.strBody = Chr(KeyAscii) OutMsg.strLabel = "Key: " + OutMsg.strBody OutMsg.Send FriendQ

33 MSMQMessage.body The body property allows you to send/receive typed messages The body property allows you to send/receive typed messages Messages can be: Messages can be: Strings Strings Arrays of bytes Arrays of bytes Persistent ActiveX objects Persistent ActiveX objects Support IDispatch and IPersistStream or IPersistStorage Support IDispatch and IPersistStream or IPersistStorage E.g., Office documents, bitmaps E.g., Office documents, bitmaps

34 Example send/receive an XL sheet Dim mSend as New MSMQMessage Dim mReceive as MSMQMessage Dim qSend as MSMQQueue Dim qReceive as MSMQQueue mSend.body = GetObject(sheet.xls) mSend.Send qSend set mReceive = qReceive.Receive if TypeOf mReceive.body Is Excel.Workbook Then do XL stuff to message body set xl = mReceive.body end if

35 Limitations Only Visual Basic 5.0 supports user-defined event handlers to ActiveX Servers Only Visual Basic 5.0 supports user-defined event handlers to ActiveX Servers Use WithEvents keyword in declaration Use WithEvents keyword in declaration Visual Basic 4.0 can use every other feature Visual Basic 4.0 can use every other feature Visual Basic 5.0 example: Open an existing queue for asynchronous reception Dim WithEvents qevent As MSMQEvent Sub OpenExistingQueue() Dim qinfo As New MSMQQueueInfo qinfo.strPathName = "machine\queue" Set qPeek = qrec.Open(MQMSG_PEEK_ACCESS, 0) Set qevent = New MSMQEvent qPeek.EnableNotification qevent End Sub Private Sub qevent_Arrived(byval q as Object) Dim m As MSMQMessage Set m = q.PeekNext MsgBox "Arrived: " + m.strBody q.EnableNotification qevent End Sub Visual Basic 5.0 example: Open an existing queue for asynchronous reception Dim WithEvents qevent As MSMQEvent Sub OpenExistingQueue() Dim qinfo As New MSMQQueueInfo qinfo.strPathName = "machine\queue" Set qPeek = qrec.Open(MQMSG_PEEK_ACCESS, 0) Set qevent = New MSMQEvent qPeek.EnableNotification qevent End Sub Private Sub qevent_Arrived(byval q as Object) Dim m As MSMQMessage Set m = q.PeekNext MsgBox "Arrived: " + m.strBody q.EnableNotification qevent End Sub

36 Summary Your mission Your mission Today: try Beta2 Today: try Beta2 Run the samples (c_draw and oa_draw) Run the samples (c_draw and oa_draw) Write applications using the C/C++ API and ActiveX Components Write applications using the C/C++ API and ActiveX Components Soon: deploy Falcon-based message queuing applications Soon: deploy Falcon-based message queuing applications

37 Summary Your benefit Your benefit Easy and flexible distributed programming Easy and flexible distributed programming Asynchronous, sessionless messaging Asynchronous, sessionless messaging Not concerned with underlying network and protocols Not concerned with underlying network and protocols Not concerned with computer and network reliability Not concerned with computer and network reliability Integrated with state-of-the-art technologies and interfaces Integrated with state-of-the-art technologies and interfaces ActiveX Components usable from Visual Basic Scripting Edition (e.g., Denali) ActiveX Components usable from Visual Basic Scripting Edition (e.g., Denali)

38 Questions? For more information For more information See slides from Microsoft Message Queue Server Overview (ENT208) talk See slides from Microsoft Message Queue Server Overview (ENT208) talk Check out our Web site: http://www.microsoft.com/msmq Check out our Web site: http://www.microsoft.com/msmq Contact msmq@microsoft.com Contact msmq@microsoft.com

39


Download ppt "Programming A Distributed Message Queue Application Raphi Renous Software Development Engineer Desktop And Business Systems Division Microsoft Corporation."

Similar presentations


Ads by Google