+ All Categories
Home > Documents > Programming A Distributed Message Queue Application Raphi Renous Software Development Engineer...

Programming A Distributed Message Queue Application Raphi Renous Software Development Engineer...

Date post: 26-Mar-2015
Category:
Upload: irea-kelley
View: 217 times
Download: 2 times
Share this document with a friend
Popular Tags:
39
Programming A Programming A Distributed Message Distributed Message Queue Application Queue Application Raphi Renous Raphi Renous Software Development Software Development Engineer Engineer Desktop And Business Desktop And Business Systems Division Systems Division Microsoft Corporation Microsoft Corporation
Transcript
Page 1: Programming A Distributed Message Queue Application Raphi Renous Software Development Engineer Desktop And Business Systems Division Microsoft Corporation.

Programming A Programming A Distributed Message Distributed Message Queue ApplicationQueue Application

Raphi RenousRaphi RenousSoftware Development EngineerSoftware Development EngineerDesktop And Business Desktop And Business Systems DivisionSystems DivisionMicrosoft CorporationMicrosoft Corporation

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

AgendaAgenda

““Falcon” (MSMQ) featuresFalcon” (MSMQ) features Distributed whiteboard demoDistributed whiteboard demo C/C++ APIC/C++ API ActiveXActiveX™™ Components Components SummarySummary Questions?Questions?

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

““Falcon” (MSMQ) FeaturesFalcon” (MSMQ) Features

Sessionless with asynchronous Sessionless with asynchronous send and receivesend and receive

Protocol and platform-independent APIProtocol and platform-independent API Scalable to large number of nodesScalable to large number of nodes Robust: reliable, guaranteed, transactional Robust: reliable, guaranteed, transactional Integrated securityIntegrated security System-wide priority policySystem-wide priority policy Advanced logging and trackingAdvanced logging and tracking Multireader, multisender, multithreaded Multireader, multisender, multithreaded Support for legacy systemsSupport for legacy systems SDK: C/C++ API, ActiveX ComponentsSDK: C/C++ API, ActiveX Components

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

DemoDemoDistributed whiteboardDistributed whiteboard

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

C/C++ APIC/C++ API

Function setsFunction sets Queue manipulationQueue manipulation Queue locationQueue location Message manipulationMessage manipulation UtilitiesUtilities

Message and queue objects Message and queue objects represented using properties represented using properties

Use MQ.H, MQRT.LIBUse MQ.H, MQRT.LIB

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

PropertiesProperties

Properties associated with queuesProperties associated with queuesand messagesand messages

Each property consists of ID, type, valueEach property consists of ID, type, value Property setProperty set

CountCount Array of IDsArray of IDs Array of variants (tagged union) containing Array of variants (tagged union) containing

type and valuetype and value Array of status codes (optional)Array of status codes (optional)

ID names: ID names: PROPID_Q_*PROPID_Q_* or or PROPID_M_*PROPID_M_*

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

Usage OverviewUsage Overview

Queue creationQueue creation Form queue property setForm queue property set CallCall MQCreateQueue() MQCreateQueue()with property setwith property set

Queue openingQueue opening Obtain queue format nameObtain queue format name

By creating the queueBy creating the queue From the queue location functionFrom the queue location function Set by the applicationSet by the application

Call Call MQOpenQueue()MQOpenQueue()with format namewith format name

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

Usage OverviewUsage Overview

Message receptionMessage reception Open queue for receive accessOpen queue for receive access Determine message property set to be receivedDetermine message property set to be received CallCall MQReceiveMessage() MQReceiveMessage() with open queue with open queue

handle and property sethandle and property set If asynchronous, write code to handle If asynchronous, write code to handle

message arrivalmessage arrival

Message sendingMessage sending Open queue for send accessOpen queue for send access Form message property setForm message property set CallCall MQSendMessage() MQSendMessage() with open with open

queue handle and property setqueue handle and property set

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

Queue ManipulationQueue Manipulation

Default security: get properties/permissions and sendDefault security: get properties/permissions and send Queue propertiesQueue properties

PATHNAME, LABEL, SERVICETYPE, INSTANCE, TRANSACTIONAL, PATHNAME, LABEL, SERVICETYPE, INSTANCE, TRANSACTIONAL, BASEPRIORITY, AUTHENTICATE, JOURNAL, PRIV_LEVEL, QUOTABASEPRIORITY, AUTHENTICATE, JOURNAL, PRIV_LEVEL, QUOTA

PATHNAME PATHNAME property specifies public/private queueproperty specifies public/private queue PublicPublic

Stored in MSMQ Information Service database Stored in MSMQ Information Service database ““MachineName\QueueName”MachineName\QueueName”

PrivatePrivate Stored on disk of local machineStored on disk of local machine ““MachineName\Private$\QueueName”MachineName\Private$\QueueName”

HRESULT HRESULT MQCreateQueueMQCreateQueue(IN PSECURITY_DESCRIPTOR (IN PSECURITY_DESCRIPTOR pSecurityDescpSecurityDesc,, IN OUT MQQUEUEPROPS IN OUT MQQUEUEPROPS *pQueueProps*pQueueProps,,

OUT LPWSTR OUT LPWSTR lpwcsFormatNamelpwcsFormatName,, IN OUT LPDWORD IN OUT LPDWORD lpdwFormatNameLengthlpdwFormatNameLength))

HRESULT HRESULT MQDeleteQueueMQDeleteQueue(IN LPWSTR (IN LPWSTR lpwcsFormatNamelpwcsFormatName))

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

Format nameFormat name Specifies how to get to a queueSpecifies how to get to a queue

““Public=QueueInstance”Public=QueueInstance” ““Private=MachineGUID\QueueInstance”Private=MachineGUID\QueueInstance” ““Direct=Protocol:MachineAddress\Direct=Protocol:MachineAddress\

QueueName”QueueName”“Direct=OS:MachineAddress\QueueName”“Direct=OS:MachineAddress\QueueName”

Not a propertyNot a property Returned byReturned by MQCreateQueue() MQCreateQueue() Obtained from the properties returnedObtained from the properties returned

by the queue location functionsby the queue location functions Formed by the applicationFormed by the application

Queue ManipulationQueue Manipulation

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

Subject to queue securitySubject to queue security One type of access per queue handleOne type of access per queue handle

MQ_SEND_ACCESS, MQ_RECEIVE_ACCESS, MQ_PEEK_ACCESSMQ_SEND_ACCESS, MQ_RECEIVE_ACCESS, MQ_PEEK_ACCESS

Share modeShare mode 00 - available to everyone (must be used for peek and send) - available to everyone (must be used for peek and send) MQ_DENY_RECEIVE_SHARE MQ_DENY_RECEIVE_SHARE - only this process can receive- only this process can receive

HRESULT HRESULT MQOpenQueueMQOpenQueue(IN LPWSTR (IN LPWSTR lpwcsFormatNamelpwcsFormatName,, IN DWORD IN DWORD dwAccessdwAccess,, IN DWORD IN DWORD dwShareModedwShareMode,, OUT LPQUEUEHANDLE OUT LPQUEUEHANDLE phQueuephQueue))

HRESULT HRESULT MQCloseQueueMQCloseQueue(IN QUEUEHANDLE (IN QUEUEHANDLE hQueuehQueue))

Queue ManipulationQueue Manipulation

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

QUEUEPROPID QUEUEPROPID aPropIdaPropId[1];[1];MQPROPVARIANT MQPROPVARIANT aPropVaraPropVar[1];[1];DWORD DWORD cPropscProps = 0;= 0;aPropIdaPropId[[cPropscProps] ] = = PROPID_Q_PATHNAMEPROPID_Q_PATHNAME;;aPropVaraPropVar[[cPropscProps].].vtvt = = VT_LPWSTRVT_LPWSTR;;aPropVaraPropVar[[cPropscProps].].pwszValpwszVal = = LL“machine\\queue”;“machine\\queue”;cPropscProps++;++;

MQQUEUEPROPS MQQUEUEPROPS propsQueuepropsQueue;;propsQueuepropsQueue..cPropscProps = = cPropscProps;;propsQueuepropsQueue..aPropIdaPropId = = aPropIdaPropId;;propsQueuepropsQueue..aPropVaraPropVar = = aPropVaraPropVar;;propsQueuepropsQueue..aStatusaStatus = NULL; = NULL;

WCHAR WCHAR szFormatszFormat[[MAX_FORMAT_NAME_LENMAX_FORMAT_NAME_LEN];];DWORD DWORD dwSizedwSize = = MAX_FORMAT_NAME_LENMAX_FORMAT_NAME_LEN;;HRESULTHRESULT hrhr = = MQCreateQueueMQCreateQueue(NULL, &(NULL, &propsQueuepropsQueue, , szFormatszFormat, &, &dwSizedwSize););

QUEUEHANDLE QUEUEHANDLE hQueuehQueue;;if (!FAILED(if (!FAILED(hrhr)))) hrhr = = MQOpenQueueMQOpenQueue((szFormatszFormat, , MQ_RECEIVE_ACCESSMQ_RECEIVE_ACCESS, 0, &, 0, &hQueuehQueue););

Queue ManipulationQueue Manipulation

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

Queue LocationQueue Location

Powerful - do not need to know exact location of queuePowerful - do not need to know exact location of queue Context - starting point in name space (currently Context - starting point in name space (currently NULLNULL)) Restriction setRestriction set

Property information (ID, type, value)Property information (ID, type, value) Comparison operation for each propertyComparison operation for each property

Column set - queue properties to be returned by queryColumn 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 setProperty IDs from column set Order for each property IDOrder for each property ID

Returns enumeration handle (does not retrieve results)Returns enumeration handle (does not retrieve results)

HRESULT HRESULT MQLocateBeginMQLocateBegin(IN LPCWSTR (IN LPCWSTR lpwcsContextlpwcsContext,, IN MQRESTRICTION IN MQRESTRICTION *pRestriction*pRestriction,,

IN MQCOLUMNSET IN MQCOLUMNSET *pColumns*pColumns,, IN MQSORTSET IN MQSORTSET *pSort*pSort,, OUT PHANDLE OUT PHANDLE phEnumphEnum))

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

Call MQLocateNext() until (*pcProps) Call MQLocateNext() until (*pcProps) on output < (*pcProps) on inputon output < (*pcProps) on input

Returns as many “complete” results as possibleReturns as many “complete” results as possible Must free memory allocated by “Falcon” (if any) Must free memory allocated by “Falcon” (if any)

using MQFreeMemory()using MQFreeMemory()

HRESULT HRESULT MQLocateNextMQLocateNext(IN HANDLE (IN HANDLE hEnumhEnum,, IN OUT DWORD IN OUT DWORD *pcProps*pcProps,, OUT PROPVARIANT OUT PROPVARIANT aPropVar[]aPropVar[]))

HRESULT HRESULT MQLocateEndMQLocateEnd(IN HANDLE (IN HANDLE hEnumhEnum))

Queue LocationQueue Location

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

MQPROPERTYRESTRICTION MQPROPERTYRESTRICTION aPropRestrictionaPropRestriction[1];[1];DWORD DWORD cPropscProps = 0;= 0;aPropRestrictionaPropRestriction[[cPropscProps].].relrel == PREQPREQ;;aPropRestrictionaPropRestriction[[cPropscProps].].propprop == PROPID_Q_LABELPROPID_Q_LABEL;;aPropRestrictionaPropRestriction[[cPropscProps].].prvalprval..vtvt == VT_LPWSTRVT_LPWSTR;;aPropRestrictionaPropRestriction[[cPropscProps].].prvalprval..pwszValpwszVal == LL“label”;“label”;cPropscProps++;++;MQRESTRICTION MQRESTRICTION RestrictionRestriction;;RestrictionRestriction..cRescRes = = cPropscProps;;RestrictionRestriction..paPropRespaPropRes = = aPropRestrictionaPropRestriction;;

QUEUEPROPID QUEUEPROPID aPropIdaPropId[1];[1];cPropscProps = 0;= 0; aPropIdaPropId[[cPropscProps] = ] = PROPID_Q_INSTANCEPROPID_Q_INSTANCE;;cPropscProps++;++;MQCOLUMNSET MQCOLUMNSET ColumnColumn;;ColumnColumn..cColcCol = = cPropscProps;;ColumnColumn..aColaCol = = aPropIdaPropId;;

Queue LocationQueue Location

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

DWORD DWORD hEnumhEnum;;HRESULTHRESULT hrhr = = MQLocateBeginMQLocateBegin(NULL, &(NULL, &RestrictionRestriction, &, &ColumnColumn, ,

NULL, &NULL, &hEnumhEnum););if (!FAILED(if (!FAILED(hrhr)))){{ MQPROPVARIANT MQPROPVARIANT aPropVaraPropVar[1];[1]; DWORD DWORD cQueuecQueue = 1;= 1; hrhr = = MQLocateNextMQLocateNext((hEnumhEnum, &, &cQueuecQueue, &, &ColumnColumn, , aPropVaraPropVar);); if (!FAILED(if (!FAILED(hrhr) && ) && cQueuecQueue > 0)> 0) {{ WCHAR WCHAR szFormatszFormat[[MAX_FORMAT_NAME_LENMAX_FORMAT_NAME_LEN];]; DWORD DWORD dwSizedwSize = = MAX_FORMAT_NAME_LENMAX_FORMAT_NAME_LEN;; hrhr = = MQGuidToFormatNameMQGuidToFormatName((aPropVaraPropVar[0].[0].puuidpuuid, ,

szFormatszFormat, &, &dwSizedwSize);); if (!FAILED(if (!FAILED(hrhr)))) ... /* Open queue */... /* Open queue */

MQFreeMemoryMQFreeMemory((apropVarapropVar[0].[0].puuidpuuid);); }} MQLocateEndMQLocateEnd((hEnumhEnum););}}

Queue LocationQueue Location

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

Message ManipulationMessage Manipulation

Message propertiesMessage properties BODY, LABEL, DELIVERY, PRIORITY, TIME_TO_BE_RECEIVED, BODY, LABEL, DELIVERY, PRIORITY, TIME_TO_BE_RECEIVED,

TIME_TO_REACH_QUEUE, JOURNAL, ACKNOWLEDGE, TIME_TO_REACH_QUEUE, JOURNAL, ACKNOWLEDGE, CORRELATIONID, APPSPECIFIC, ADMIN_QUEUE, CORRELATIONID, APPSPECIFIC, ADMIN_QUEUE, RESPONSE_QUEUE, PRIVACYLEVEL, SECURITY_CONTEXTRESPONSE_QUEUE, PRIVACYLEVEL, SECURITY_CONTEXT

Always asynchronousAlways asynchronous UseUse TIME_TO_BE_RECEIVED TIME_TO_BE_RECEIVED oror TIME_TO_REACH_QUEUE TIME_TO_REACH_QUEUE property property

to specify time limit for message to reach destinationto specify time limit for message to reach destination

Transaction interfaceTransaction interface Get from MSGet from MS®® DTC DTC

HRESULT HRESULT MQSendMessageMQSendMessage(IN QUEUEHANDLE (IN QUEUEHANDLE hDestinationQueuehDestinationQueue,, IN MQMSGPROPS IN MQMSGPROPS ** pMessagePropspMessageProps,, IN ITransaction IN ITransaction ** pTransactionpTransaction))

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

ActionAction MQ_ACTION_RECEIVE, MQ_ACTION_PEEK_CURRENT, MQ_ACTION_RECEIVE, MQ_ACTION_PEEK_CURRENT,

MQ_ACTION_PEEK_NEXTMQ_ACTION_PEEK_NEXT Additional message propertiesAdditional message properties

CLASS, MSGID, SENDERID, SRC_MACHINE, SENDER_CERTIFICATECLASS, MSGID, SENDERID, SRC_MACHINE, SENDER_CERTIFICATE Allows asynchronous receiveAllows asynchronous receive

Callback function, Win32Callback function, Win32®® event, Windows NT event, Windows NT®® completion port completion port Cursor used to traverse messages in queueCursor used to traverse messages in queue Transaction interfaceTransaction interface

Get from MS DTCGet from MS DTC

HRESULT HRESULT MQReceiveMessageMQReceiveMessage(IN QUEUEHANDLE (IN QUEUEHANDLE hSourceQueuehSourceQueue, , IN DWORD IN DWORD dwTimeOutdwTimeOut,, IN DWORD IN DWORD dwActiondwAction, , IN OUT MQMSGPROPS IN OUT MQMSGPROPS *pMessageProps*pMessageProps,, IN OUT LPOVERLAPPED IN OUT LPOVERLAPPED lpOverlappedlpOverlapped,, IN PMQRECEIVECALLBACK IN PMQRECEIVECALLBACK fnReceiveCallbackfnReceiveCallback,, IN HANDLE IN HANDLE hCursor,hCursor, IN ITransaction IN ITransaction ** pTransactionpTransaction))

Message ManipulationMessage Manipulation

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

MSGPROPID MSGPROPID aPropIdaPropId[1];[1];MQPROPVARIANT MQPROPVARIANT aPropVaraPropVar[1];[1];DWORD DWORD cPropscProps = 0;= 0;WCHAR WCHAR szBodyszBody[[MAX_MSG_BODY_LENMAX_MSG_BODY_LEN];];aPropIdaPropId[[cPropscProps] ] = = PROPID_M_BODYPROPID_M_BODY;;aPropVaraPropVar[[cPropscProps].].vtvt = = VT_UI1 VT_UI1 || VT_VECTOR VT_VECTOR;;aPropVaraPropVar[[cPropscProps].].cabcab..cElemscElems = sizeof(= sizeof(szBodyszBody););aPropVaraPropVar[[cPropscProps].].cabcab..pElemspElems = (UCHAR *)= (UCHAR *)szBodyszBody;;cPropscProps++;++;

MQMSGPROPS MQMSGPROPS propsMsgpropsMsg;;propsMsgpropsMsg..cPropscProps = = cPropscProps;;propsMsgpropsMsg..aPropIdaPropId = = aPropIdaPropId;;propsMsgpropsMsg..aPropVaraPropVar = = aPropVaraPropVar;;propsMsgpropsMsg..aStatusaStatus = NULL; = NULL;

HRESULTHRESULT hrhr = = MQReceiveMessageMQReceiveMessage((hQueuehQueue,, INFINITEINFINITE,, MQ_ACTION_RECEIVE MQ_ACTION_RECEIVE,, &&propsMsgpropsMsg, , NULL, NULL, NULL, NULL);NULL, NULL, NULL, NULL);

Message ManipulationMessage Manipulation

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

Other FunctionsOther Functions

Queue manipulationQueue manipulation MQGetQueueProperties(), MQGetQueueProperties(),

MQSetQueueProperties()MQSetQueueProperties() MQGetQueueSecurity(), MQGetQueueSecurity(),

MQSetQueueSecurity()MQSetQueueSecurity() Message manipulationMessage manipulation

MQCreateCursor(), MQCloseCursor()MQCreateCursor(), MQCloseCursor() UtilitiesUtilities

MQFreeMemory() MQFreeMemory() MQGetMachineProperties() MQGetMachineProperties() MQGuidToFormatName(), MQGuidToFormatName(),

MQHandleToFormatName(), MQHandleToFormatName(), MQPathNameToFormatName()MQPathNameToFormatName()

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

ActiveX ComponentsActiveX Components

Provide simple end-user programming modelProvide simple end-user programming modelwithout compromising performancewithout compromising performance

Support early (vtable) and late (Support early (vtable) and late (IDispatchIDispatch) binding) binding Direct support for most “Falcon” functionalityDirect support for most “Falcon” functionality

within the object modelwithin 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 BasicVisual Basic®® 3.0, Visual Basic 4.0, Visual Basic 5.0 3.0, Visual Basic 4.0, Visual Basic 5.0 ““Denali”Denali” MicrosoftMicrosoft®® Access Access Office 97Office 97

Delphi, PowerBuilderDelphi, PowerBuilder

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

Component ModelComponent Model

MSMQQueueInfoMSMQQueueInfo: queue object: queue object MSMQQueueMSMQQueue: instance of open queue: instance of open queue MSMQMessageMSMQMessage: message object: message object MSMQQueryMSMQQuery: supports queue location: supports queue location MSMQQueueInfosMSMQQueueInfos: collection of queues: collection of queues MSMQEventMSMQEvent:: asynchronous message asynchronous message

arrival notificationarrival notification Deliverable: mqoa.dllDeliverable: mqoa.dll

Contains both implementation and type libraryContains both implementation and type library

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

Usage OverviewUsage Overview

Queue creationQueue creation Set properties inSet properties in MSMQQueueInfo MSMQQueueInfo CallCall MSMQQueueInfo.Create MSMQQueueInfo.Create

Queue openingQueue opening ObtainObtain MSMQQueueInfo MSMQQueueInfo

By creating the queueBy creating the queue FromFrom MSMQQueueInfos MSMQQueueInfos

returned byreturned by MSMQQuery MSMQQuery SetSet q q == queueinfo.Open queueinfo.Open

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

Usage OverviewUsage Overview

Message receptionMessage reception mqQueue mqQueue = queue opened with receive access= queue opened with receive access If asynchronousIf asynchronous

Create Create MSMQEvent MSMQEvent object:object:set qevent = new MSMQEventset qevent = new MSMQEvent

CallCall mqQueue.EnableNotification(qevent) mqQueue.EnableNotification(qevent) WriteWrite qevent_Arrived qevent_Arrived event handlerevent handler

SetSet mqMessage mqMessage == mqQueue.Receive mqQueue.Receive Message sendingMessage sending

mqQueue mqQueue = queue opened with send access= queue opened with send access Set properties inSet properties in mqMessage mqMessage instance instance CallCall mqMessage.Send(mqQueue) mqMessage.Send(mqQueue)

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

MSMQQueueInfoMSMQQueueInfo

Describes a queue objectDescribes a queue object MethodsMethods

Create, DeleteCreate, Delete Open(access, sharemode) as MSMQQueueOpen(access, sharemode) as MSMQQueue

access: MQMSG_RECEIVE_ACCESS,access: MQMSG_RECEIVE_ACCESS,MQMSG_SEND_ACCESS, MQMSG_SEND_ACCESS,

MQMSG_PEEK_ACCESSMQMSG_PEEK_ACCESS sharemode: MQ_DENY_NONE, MQ_DENY_RECEIVE_SHAREsharemode: MQ_DENY_NONE, MQ_DENY_RECEIVE_SHARE

PropertiesProperties strLabel, strPathname, guidServiceType, guidQueue, strLabel, strPathname, guidServiceType, guidQueue,

strFormatNamestrFormatName

ExampleExample‘ Create queue for my instance‘ Create queue for my instanceDim qrec As New MSMQQueueInfoDim qrec As New MSMQQueueInfoqinfo.strPathName = "machine\queue"qinfo.strPathName = "machine\queue"qinfo.strLabel = "My Draw Queue"qinfo.strLabel = "My Draw Queue"qinfo.Createqinfo.Create

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

MSMQQueueMSMQQueue

Describes an open queue instanceDescribes an open queue instance A queue can be concurrently open A queue can be concurrently open

multiple timesmultiple times One-to-many mapping from One-to-many mapping from

MSMQQueueInfoMSMQQueueInfo to to MSMQQueueMSMQQueue Analogy: Analogy: MSMQQueueInfoMSMQQueueInfo is to is to

MSMQQueueMSMQQueue as as FileFile is to is to FileHandleFileHandle Provides asynchronous Provides asynchronous

message handlingmessage handling Manages collection of messagesManages collection of messages

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

MSMQQueueMSMQQueue

MethodsMethods IsOpen() as BooleanIsOpen() as Boolean CloseClose Receive() as MSMQMessageReceive() as MSMQMessage

Synchronous message receptionSynchronous message reception Peek() as MSMQMessagePeek() as MSMQMessage

Synchronous message peekingSynchronous message peeking EnableNotification(qevent as MSMQEvent)EnableNotification(qevent as MSMQEvent)

Turns on asynchronous message notificationTurns on asynchronous message notification Message arrival to queue will now fire Message arrival to queue will now fire qevent_qevent_

ArrivedArrived event event DisableNotificationDisableNotification ResetReset

Resets message collection to startResets message collection to start ReceiveNext() / PeekNext() as MSMQMessageReceiveNext() / PeekNext() as MSMQMessage

Cursor based synchronous reception/peekCursor based synchronous reception/peek

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

MSMQQueueMSMQQueue

PropertiesProperties lReceiveTimeout, lAccess, lShareMode, queueinfo, lReceiveTimeout, lAccess, lShareMode, queueinfo,

lHandlelHandle Error event fired if timeout expires while synchronously Error event fired if timeout expires while synchronously

waiting to receive messagewaiting to receive message

ExampleExample‘ Create and open a queue for synchronous reception‘ Create and open a queue for synchronous receptionDim qinfo As New MSMQQueueInfoDim qinfo As New MSMQQueueInfoDim myQ As MSMQQueue Dim myQ As MSMQQueue qinfo.strPathName = "machine\queue" qinfo.strPathName = "machine\queue" qinfo.Createqinfo.CreateSet myQ = qinfo.Open(MQMSG_RECEIVE_ACCESS, Set myQ = qinfo.Open(MQMSG_RECEIVE_ACCESS, MQ_DENY_NONE)MQ_DENY_NONE)

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

MSMQEventMSMQEvent

Allows user to write single generic Allows user to write single generic event handler to manage message event handler to manage message arrival notification of multiple queuesarrival notification of multiple queues

EventsEvents Arrived(byval pdispQueue as Object)Arrived(byval pdispQueue as Object)

Fired when a new message arrives Fired when a new message arrives at queueat queue

ArrivedError(byval pdispQueue as Object, ArrivedError(byval pdispQueue as Object, byval error as Long)byval error as Long) Fired to indicate message error Fired to indicate message error

in receptionin reception

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

MSMQQueryMSMQQuery

Provides filtered queue location Provides filtered queue location Returns collection of queue objectsReturns collection of queue objects MethodMethod

LookupQueue(<selection criteria>) as MSMQQueueInfosLookupQueue(<selection criteria>) as MSMQQueueInfos

ExampleExample‘ Locate the friend queue‘ Locate the friend queueDim queryFriend As New MqQueryDim queryFriend As New MqQueryDim qinfosResult As MSMQQueueInfosDim qinfosResult As MSMQQueueInfosSet qinfosResult = queryFriend.LookupQueue(Set qinfosResult = queryFriend.LookupQueue(

strLabel := FriendName,strLabel := FriendName,strGuidServiceType := strGuidServiceType :=

DrawType)DrawType)

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

MSMQQueueInfosMSMQQueueInfos

Manages collection of Manages collection of MSMQQueueInfoMSMQQueueInfo objects produced by objects produced by MSMQQueryMSMQQuery

MethodsMethods ResetReset Next() as MSMQQueueInfoNext() as MSMQQueueInfo

ExampleExample‘ ‘ Display the queue label for all the queuesDisplay the queue label for all the queuesDim queryAll As New MSMQQueryDim queryAll As New MSMQQueryDim qinfos As MSMQQueueInfosDim qinfos As MSMQQueueInfosDim qinfoCurrent As MSMQQueueInfoDim qinfoCurrent As MSMQQueueInfoSet qinfos = queryAll.LookupQueueSet qinfos = queryAll.LookupQueueqinfos.Resetqinfos.ResetSet qinfoCurrent = qinfos.NextSet qinfoCurrent = qinfos.NextWhile Not qinfoCurrent Is NothingWhile Not qinfoCurrent Is Nothing MsgBox qinfoCurrent.strLabel MsgBox qinfoCurrent.strLabel Set qinfoCurrent = qinfos.Next Set qinfoCurrent = qinfos.NextWendWend

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

MSMQMessageMSMQMessage

Describes a messageDescribes a message MethodMethod

Send(q as MSMQQueue)Send(q as MSMQQueue)

PropertiesProperties body, strLabel, delivery, lPriority, body, strLabel, delivery, lPriority,

lTimeToBeReceived, lTimeToReachQueue, class, id, lTimeToBeReceived, lTimeToReachQueue, class, id, idCorrelation, lJournal, acknowledge, idCorrelation, lJournal, acknowledge, queueinfoResponse, queueinfoAdmin, queueinfoResponse, queueinfoAdmin, queueinfoDest, lAppSpecificqueueinfoDest, lAppSpecific

ExampleExample‘ Send the keystroke to the friend‘ Send the keystroke to the friendDim OutMsg as New MSMQMessageDim OutMsg as New MSMQMessageOutMsg.lPriority = 4OutMsg.lPriority = 4OutMsg.strBody = Chr(KeyAscii)OutMsg.strBody = Chr(KeyAscii)OutMsg.strLabel = "Key: " + OutMsg.strBodyOutMsg.strLabel = "Key: " + OutMsg.strBodyOutMsg.Send FriendQOutMsg.Send FriendQ

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

MSMQMessage.bodyMSMQMessage.body

The The bodybody property allows you property allows you to send/receive typed messagesto send/receive typed messages

Messages can be:Messages can be: StringsStrings Arrays of bytesArrays of bytes Persistent ActiveX objectsPersistent ActiveX objects

Support Support IDispatch IDispatch and and IPersistStreamIPersistStream or or IPersistStorageIPersistStorage

E.g., Office documents, bitmapsE.g., Office documents, bitmaps

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

ExampleExample

‘ send/receive an XL sheetDim mSend as New MSMQMessageDim mReceive as MSMQMessageDim qSend as MSMQQueueDim 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.bodyend if

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

LimitationsLimitations

Only Visual Basic 5.0 supports user-defined Only Visual Basic 5.0 supports user-defined event handlers to ActiveX Serversevent handlers to ActiveX Servers Use Use WithEventsWithEvents keyword in declaration keyword in declaration

Visual Basic 4.0 can use every other featureVisual Basic 4.0 can use every other feature Visual Basic 5.0 example:Visual Basic 5.0 example:

‘ Open an existing queue for asynchronous reception‘ Open an existing queue for asynchronous receptionDim WithEvents qevent As MSMQEventDim WithEvents qevent As MSMQEventSub OpenExistingQueue()Sub OpenExistingQueue() Dim qinfo As New MSMQQueueInfo Dim qinfo As New MSMQQueueInfo qinfo.strPathName = "machine\queue" qinfo.strPathName = "machine\queue" Set qPeek = qrec.Open(MQMSG_PEEK_ACCESS, 0) Set qPeek = qrec.Open(MQMSG_PEEK_ACCESS, 0) Set qevent = New MSMQEvent Set qevent = New MSMQEvent qPeek.EnableNotification qevent qPeek.EnableNotification qeventEnd SubEnd SubPrivate Sub qevent_Arrived(byval q as Object)Private Sub qevent_Arrived(byval q as Object) Dim m As MSMQMessage Dim m As MSMQMessage Set m = q.PeekNext Set m = q.PeekNext MsgBox "Arrived: " + m.strBody MsgBox "Arrived: " + m.strBody

q.EnableNotification qevent q.EnableNotification qeventEnd SubEnd Sub

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

SummarySummary

Your missionYour mission Today: try Beta2Today: 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 Write applications using the C/C++ API

and ActiveX Componentsand ActiveX Components Soon: deploy “Falcon”-based message Soon: deploy “Falcon”-based message

queuing applicationsqueuing applications

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

SummarySummary

Your benefitYour benefit Easy and flexible distributed programmingEasy and flexible distributed programming

Asynchronous, sessionless messagingAsynchronous, sessionless messaging Not concerned with underlying networkNot concerned with underlying network

and protocolsand protocols Not concerned with computer Not concerned with computer

and network reliabilityand network reliability Integrated with state-of-the-art Integrated with state-of-the-art

technologies and interfacestechnologies and interfaces ActiveX Components usable fromActiveX Components usable from

Visual Basic Scripting Edition Visual Basic Scripting Edition (e.g., “Denali”)(e.g., “Denali”)

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

Questions?Questions?

For more informationFor more information See slides from “Microsoft Message See slides from “Microsoft Message

Queue Server Overview (ENT208)” talkQueue Server Overview (ENT208)” talk Check out our Web site: Check out our Web site:

http://www.microsoft.com/msmqhttp://www.microsoft.com/msmq Contact [email protected] [email protected]

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


Recommended