테스트 메시지 보내기

Microsoft.MSMQ.10.0.DataSource.Queue.SendTestMessage (DataSourceModuleType)

테스트 메시지를 보내 큐의 상태를 확인하기 위한 데이터 원본.

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityPublic
RunAsMicrosoft.MSMQ.10.0.QueueAccessProfile
OutputTypeSystem.PropertyBagData

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource Microsoft.Windows.TimedScript.PropertyBagProvider Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
IntervalSecondsint$Config/IntervalSeconds$간격(초)
TargetQueuestring$Config/TargetQueue$대상 큐
AdminQueuestring$Config/AdminQueue$관리자 큐
CreateQueuesbool$Config/CreateQueues$큐 만들기
AppSpecificint$Config/AppSpecific$앱 전용
MessageBodystring$Config/MessageBody$메시지 본문
RemoveMessagebool$Config/RemoveMessage$메시지 제거
CleanupQueuebool$Config/CleanupQueue$큐 정리
CleanupAdminQueuebool$Config/CleanupAdminQueue$관리자 큐 정리
LogDetailbool$Config/LogDetail$로그 세부 정보
TimeoutSecondsint$Config/TimeoutSeconds$제한 시간(초)

Source Code:

<DataSourceModuleType ID="Microsoft.MSMQ.10.0.DataSource.Queue.SendTestMessage" Accessibility="Public" RunAs="Microsoft.MSMQ.10.0.QueueAccessProfile" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="IntervalSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="ComputerName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="TargetQueue" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="AdminQueue" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="CreateQueues" type="xsd:boolean"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="AppSpecific" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="MaxWaitTime" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="MessageBody" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="RemoveMessage" type="xsd:boolean"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="CleanupQueue" type="xsd:boolean"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="CleanupAdminQueue" type="xsd:boolean"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="LogDetail" type="xsd:boolean"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="TimeoutSeconds" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="TargetQueue" Selector="$Config/TargetQueue$" ParameterType="string"/>
<OverrideableParameter ID="AdminQueue" Selector="$Config/AdminQueue$" ParameterType="string"/>
<OverrideableParameter ID="CreateQueues" Selector="$Config/CreateQueues$" ParameterType="bool"/>
<OverrideableParameter ID="AppSpecific" Selector="$Config/AppSpecific$" ParameterType="int"/>
<OverrideableParameter ID="MessageBody" Selector="$Config/MessageBody$" ParameterType="string"/>
<OverrideableParameter ID="RemoveMessage" Selector="$Config/RemoveMessage$" ParameterType="bool"/>
<OverrideableParameter ID="CleanupQueue" Selector="$Config/CleanupQueue$" ParameterType="bool"/>
<OverrideableParameter ID="CleanupAdminQueue" Selector="$Config/CleanupAdminQueue$" ParameterType="bool"/>
<OverrideableParameter ID="LogDetail" Selector="$Config/LogDetail$" ParameterType="bool"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedScript.PropertyBagProvider">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<SyncTime/>
<ScriptName>QueueSendTestMessage.vbs</ScriptName>
<Arguments>"$Config/TargetQueue$" "$Config/AdminQueue$" "$Config/MessageBody$" $Config/CreateQueues$ "$Config/AppSpecific$" $Config/MaxWaitTime$ $Config/RemoveMessage$ $Config/CleanupQueue$ $Config/CleanupAdminQueue$ $Config/LogDetail$ $Config/ComputerName$</Arguments>
<ScriptBody><Script>option explicit
SetLocale("en-us")

Const SCRIPT_NAME = "QueueSendTestMessage.vbs"

Const MQ_RECEIVE_ACCESS = 1
Const MQ_SEND_ACCESS = 2
Const MQ_PEEK_ACCESS = 32
Const MQ_ADMIN_ACCESS = 128

Const MQ_DENY_NONE = 0
Const MQ_DENY_RECEIVE_SHARE = 1

Const MQMSG_JOURNAL_NONE = 0
Const MQMSG_DEADLETTER = 1
Const MQMSG_JOURNAL = 2

Const MQMSG_DELIVERY_EXPRESS = 0
Const MQMSG_DELIVERY_RECOVERABLE = 1

Const MQMSG_ACKNOWLEDGMENT_NONE = 0
Const MQMSG_ACKNOWLEDGMENT_POS_ARRIVAL = 1
Const MQMSG_ACKNOWLEDGMENT_POS_RECEIVE = 2
Const MQMSG_ACKNOWLEDGMENT_NEG_ARRIVAL = 4
Const MQMSG_ACKNOWLEDGMENT_NEG_RECEIVE = 8
Const MQMSG_ACKNOWLEDGMENT_NACK_REACH_QUEUE = 4
Const MQMSG_ACKNOWLEDGMENT_FULL_REACH_QUEUE = 5
Const MQMSG_ACKNOWLEDGMENT_NACK_RECEIVE = 12
Const MQMSG_ACKNOWLEDGMENT_FULL_RECEIVE = 14

Const MQMSG_CLASS_NORMAL = 0
Const MQMSG_CLASS_REPORT = 1
Const MQMSG_CLASS_ACK_REACH_QUEUE = 2
Const MQMSG_CLASS_ACK_RECEIVE = 4
Const MQMSG_CLASS_NACK_BAD_DST_Q = 8
Const MQMSG_CLASS_NACK_PURGED = 9
Const MQMSG_CLASS_NACK_REACH_QUEUE_TIMEOUT = 10
Const MQMSG_CLASS_NACK_Q_EXCEED_QUOTA = 11
Const MQMSG_CLASS_NACK_ACCESS_DENIED = 12
Const MQMSG_CLASS_NACK_HOP_COUNT_EXCEEDED = 13
Const MQMSG_CLASS_NACK_BAD_SIGNATURE = 14
Const MQMSG_CLASS_NACK_BAD_ENCRYPTION = 15
Const MQMSG_CLASS_NACK_COULD_NOT_ENCRYPT = 16
Const MQMSG_CLASS_NACK_NOT_TRANSACTIONAL_Q = 17
Const MQMSG_CLASS_NACK_NOT_TRANSACTIONAL_MSG = 18
Const MQMSG_CLASS_NACK_UNSUPPORTED_CRYPTO_PROVIDER = 19
Const MQMSG_CLASS_NACK_SOURCE_COMPUTER_GUID_CHANGED = 20
Const MQMSG_CLASS_NACK_Q_DELETED = 12
Const MQMSG_CLASS_NACK_Q_PURGED = 13
Const MQMSG_CLASS_NACK_RECEIVE_TIMEOUT = 14
Const MQMSG_CLASS_NACK_RECEIVE_TIMEOUT_AT_SENDER = 15

Const EVENT_LEVEL_ERROR = 1
Const EVENT_LEVEL_WARNING = 2
Const EVENT_LEVEL_INFO = 4

Const EVENTNO_SCRIPTSTARTED = 14401
Const EVENTNO_SCRIPTENDED = 14402
Const EVENTNO_TARGETQUEUE = 14411
Const EVENTNO_ADMINQUEUE = 14412
Const EVENTNO_CREATEMESSAGE = 14413
Const EVENTNO_SENDINGMESSAGE = 14414
Const EVENTNO_WAITING = 14415
Const EVENTNO_REMOVEMESSAGE = 14416
Const EVENTNO_REMOVEMESSAGE_ERROR = 14417

Const ADMIN_TEST_QUEUE = "\Private$\MSMQTestQueue"

Dim sTargetQueue, sAdminQueue, sMessageBody, bCreateQueues
Dim lAppSpecific, iMaxWaitTime, bRemoveMessage, bCleanupQueue
Dim bCleanupAdminQueue, bLogDetail, sComputer

Dim oApi, oBag
Dim bIsCluster, WshShell, objWshShell, sName
Dim wshNetwork, sUser, sDomain, sMessage
Dim sStep
Dim oTargetQueue, oAdminQueue, q, oAdminQueueInfo, oMessage, iResult, iTotalSeconds
Dim bConnectToTargetQueue, bConnectToAdminQueue, bCreateMessage, bSendMessage, bGetResponse
Dim bScriptCompleted


sTargetQueue = WScript.Arguments(0)
sAdminQueue = WScript.Arguments(1)
sMessageBody = WScript.Arguments(2)
bCreateQueues = CBool(WScript.Arguments(3))
lAppSpecific = WScript.Arguments(4)
iMaxWaitTime = WScript.Arguments(5)
bRemoveMessage = CBool(WScript.Arguments(6))
bCleanupQueue = CBool(WScript.Arguments(7))
bCleanupAdminQueue = CBool(WScript.Arguments(8))
bLogDetail = CBool(WScript.Arguments(9))
sComputer = WScript.Arguments(10)

Set oAPI = CreateObject("MOM.ScriptAPI")
Set oBag = oAPI.CreatePropertyBag()

bIsCluster = false
If IsCluster = True then
bIsCluster = true
set WshShell = CreateObject("WScript.Shell")
set objWshShell = WshShell.Environment("Process")
sName = GetQueueServer(sComputer, ".")
objWshShell("_CLUSTER_NETWORK_NAME_") = sName
objWshShell("_CLUSTER_NETWORK_HOSTNAME_") = sName
End If

Set wshNetwork = CreateObject("WScript.Network")
sUser = wshNetwork.UserName
sDomain = wshNetwork.UserDomain
iResult = 0
iTotalSeconds = 0
bRemoveMessage = false

sMessage = "Script started. " &amp; VbCrLf &amp; _
"TargetQueue: " &amp; sTargetQueue &amp; VbCrLf &amp; _
"AdminQueue: " &amp; sAdminQueue &amp; VbCrLf &amp; _
"Computer: " &amp; wshNetwork.ComputerName &amp; VbCrLf &amp; _
"Domain: " &amp; sDomain &amp; VbCrLf &amp; _
"User: " &amp; sUser
Call LogDetail(EVENTNO_SCRIPTSTARTED,sMessage)

On Error Resume Next
bScriptCompleted = False
sStep = "Connecting to target queue."
Call LogDetail(EVENTNO_ADMINQUEUE,"Connecting to target queue: " &amp; sTargetQueue)
Set oTargetQueue = GetQueue(sTargetQueue,MQ_SEND_ACCESS,bCreateQueues)
If Err = 0 Then
bConnectToTargetQueue = True
sStep = "Connecting to admin queue."

Set q = GetQueueInfo(sTargetQueue)
If q.IsTransactional = 1 Then
sAdminQueue = GetQueueServer(sAdminQueue,"\") &amp; ADMIN_TEST_QUEUE
End If

Call LogDetail(EVENTNO_TARGETQUEUE,"Connecting to admin queue: " &amp; sAdminQueue)
Set oAdminQueue = GetQueue(sAdminQueue,MQ_RECEIVE_ACCESS,bCreateQueues)
If Err = 0 Then
bConnectToAdminQueue = True

sStep = "Creating message."
Call LogDetail(EVENTNO_CREATEMESSAGE,"Creating message." &amp; VbCrLf &amp; "Body: " &amp; sMessageBody &amp; VbCrLf &amp; "App Specific: " &amp; lAppSpecific)
Set oAdminQueueInfo = GetQueueInfo(sAdminQueue)
Set oMessage = CreateMessage(sMessageBody,lAppSpecific,MQMSG_ACKNOWLEDGMENT_FULL_REACH_QUEUE,oAdminQueueInfo,iMaxWaitTime)
If Err = 0 Then
bCreateMessage = True

sStep = "Sending message."
Call LogDetail(EVENTNO_SENDINGMESSAGE,"Sending message.")
Call Send(oMessage, oTargetQueue, sTargetQueue)
If Err = 0 Then
bSendMessage = True

sStep = "Waiting for response message."
Call LogDetail(EVENTNO_WAITING,"Waiting for response message.")
iResult = WaitForResponse(oAdminQueue,oMessage.Id,iMaxWaitTime,iTotalSeconds,bCleanupAdminQueue,lAppSpecific)
If Err = 0 Then
bGetResponse = True
bScriptCompleted = True

sStep = "Removing original message."
Call LogDetail(EVENTNO_REMOVEMESSAGE,"Removing test message from destination queue.")
If iResult &lt; 4 And bCleanupQueue Then
Set oTargetQueue = GetQueue(sTargetQueue,MQ_RECEIVE_ACCESS,False)
Call RemoveOriginalMessage(oTargetQueue,oMessage.Id)
If Err = 0 Then
bRemoveMessage = True
End If
End If
If Err = 0 Then
sStep = "Script completed."
End If

Else
bGetResponse = False
bRemoveMessage = False
End If
Else
bSendMessage= False
bGetResponse = False
bRemoveMessage = False
End If
Else
bCreateMessage = False
bSendMessage= False
bGetResponse = False
bRemoveMessage = False
End If
Else
bConnectToAdminQueue = False
bCreateMessage = False
bSendMessage= False
bGetResponse = False
bRemoveMessage = False
End If
Else
bConnectToTargetQueue = False
bConnectToAdminQueue = False
bCreateMessage = False
bSendMessage = False
bGetResponse = False
bRemoveMessage = False
End If

sMessage = "Script ended." &amp; VbCrLf &amp; _
"TargetQueue: " &amp; sTargetQueue &amp; VbCrLf &amp; _
"AdminQueue: " &amp; sAdminQueue &amp; VbCrLf &amp; _
"Domain: " &amp; sDomain &amp; VbCrLf &amp; _
"User: " &amp; sUser &amp; VbCrLf &amp; _
"Result: " &amp; iResult &amp; VbCrLf &amp; _
"Seconds: " &amp; iTotalSeconds &amp; VbCrLf &amp; _
"ConnectToTargetQueue: " &amp; bConnectToTargetQueue &amp; VbCrLf &amp; _
"ConnectToAdminQueue: " &amp; bConnectToAdminQueue &amp; VbCrLf &amp; _
"CreateMessage: " &amp; bCreateMessage &amp; VbCrLf &amp; _
"SendMessage: " &amp; bSendMessage &amp; VbCrLf &amp; _
"GetResponse: " &amp; bGetResponse &amp; VbCrLf &amp; _
"RemoveMessage: " &amp; bRemoveMessage &amp; VbCrLf &amp; _
"ScriptCompleted: " &amp; bScriptCompleted &amp; VbCrLf &amp; _
"FinalStep: " &amp; sStep &amp; VbCrLf &amp; _
"ErrorNumber: " &amp; Err.Number &amp; VbCrLf &amp; _
"ErrorDescription: " &amp; Err.Description
Call LogDetail(EVENTNO_SCRIPTENDED,sMessage)

Call oBag.AddValue("TargetQueue",sTargetQueue)
Call oBag.AddValue("AdminQueue",sAdminQueue)
Call oBag.AddValue("Domain",sDomain)
Call oBag.AddValue("User",sUser)
Call oBag.AddValue("Result",iResult)
Call oBag.AddValue("Seconds",iTotalSeconds)
Call oBag.AddValue("ConnectToTargetQueue",bConnectToTargetQueue)
Call oBag.AddValue("ConnectToAdminQueue",bConnectToAdminQueue)
Call oBag.AddValue("CreateMessage",bCreateMessage)
Call oBag.AddValue("SendMessage",bSendMessage)
Call oBag.AddValue("GetResponse",bGetResponse)
Call oBag.AddValue("RemoveMessage",bRemoveMessage)
Call oBag.AddValue("ScriptCompleted",bScriptCompleted)
Call oBag.AddValue("FinalStep",sStep)
Call oBag.AddValue("ErrorNumber",Err.Number)
Call oBag.AddValue("ErrorDescription",Err.Description)

if bIsCluster = true then

objWshShell.Remove("_CLUSTER_NETWORK_NAME_")
objWshShell.Remove("_CLUSTER_NETWORK_HOSTNAME_")
End If

Call oAPI.Return(oBag)

Function GetQueueServer(Path, Symbol)

If InStr(Path,Symbol) &gt; 0 Then
GetQueueServer = Left(Path,InStr(Path,Symbol)-1)
Else
GetQueueServer = Path
End If

End Function

Function IsCluster()
Dim wshNetwork

Set wshNetwork = CreateObject("Wscript.Network")
if StrComp(wshNetwork.ComputerName, GetQueueServer(sComputer,"."), 1) &lt;&gt; 0 then
IsCluster = True
else
IsCluster = False
End if

End Function

Function CreateMessage(Body,AppSpecific,Ack,AdminQueue,MaxTime)
Dim qm

Set qm = CreateObject("MSMQ.MSMQMessage")
qm.Delivery = MQMSG_DELIVERY_EXPRESS
qm.Ack = Ack
Set qm.AdminQueueInfo = AdminQueue
qm.Body = Body
qm.AppSpecific = AppSpecific
qm.MaxTimeToReachQueue = MaxTime
Set CreateMessage = qm

End Function

Function GetQueue(PathName,Access,CreateQueue)
Dim q, qi, Message, FormatName
On Error Resume Next
Set q = CreateObject("MSMQ.MSMQQueue")

If CreateQueue = True Then
Set qi = CreateObject("MSMQ.MSMQQueueInfo")
qi.PathName = PathName
qi.Create()
If Err = 0 Then
Message = "Queue " &amp; PathName &amp; " created by Operations Manager 2007 for testing monitor."
Call oAPI.LogScriptEvent(SCRIPT_NAME,EVENTNO_QUEUECREATED,EVENT_LEVEL_INFO,Message)
Else
Err.Clear
End If
End If

Set qi = CreateObject("MSMQ.MSMQQueueInfo")
FormatName = "DIRECT=OS:" &amp; PathName
qi.FormatName = FormatName
Set q = qi.Open(Access,MQ_DENY_NONE)
Set GetQueue = q

End Function


Function GetQueueInfo(PathName)
Dim qi
Set qi = CreateObject("MSMQ.MSMQQueueInfo")
qi.PathName = PathName
Set GetQueueInfo = qi

End Function

Sub Send(QueueMessage, TargetQueue, sTargetQueue)
Dim q, xdispenser, xact

Set q = GetQueueInfo(sTargetQueue)

If q.IsTransactional = 1 Then
Set xdispenser = CreateObject("MSMQ.MSMQTransactionDispenser") ' Used for internal transactions
Set xact = CreateObject("MSMQ.MSMQTransaction")
Set xact = xdispenser.BeginTransaction

QueueMessage.Send TargetQueue, xact
xact.Commit
Else
QueueMessage.Send TargetQueue
End If

End Sub


Function WaitForResponse(Queue,Id,MaxTimeSeconds,ByRef TotalSeconds,Cleanup,AppSpecific)
Dim dStart, MessageFound, Message
dStart = Now
MessageFound = False

Do While (MessageFound = False) And (CInt(DateDiff("s",dStart,Now)) &lt; CInt(MaxTimeSeconds))
Set Message = Queue.PeekCurrent(False,False,0)
Do While Not Message Is Nothing
If CompareId(Message.CorrelationId,Id) = True Then
TotalSeconds = DateDiff("s",dStart,Now)
If Cleanup = True Then
Set Message = Queue.ReceiveCurrent
End If
WaitForResponse = Message.MsgClass
Exit Function
Else
If Cleanup = True And CStr(Message.AppSpecific) = CStr(AppSpecific) Then
Set Message = Queue.ReceiveCurrent(False,False,0)
Set Message = Queue.PeekCurrent(False,False,0)
Else
Set Message = Queue.PeekNext(False,False,1000)
End If
End If
Loop
Loop

WaitForResponse = -1

End Function


Sub RemoveOriginalMessage(Queue,Id)
Dim MessageFound, Message
On Error Resume Next
MessageFound = False
Set Message = Queue.PeekCurrent(False,False,0)
Do While Not Message Is Nothing
If CompareId(Message.Id,Id) = True Then
MessageFound = True
Set Message = Queue.ReceiveCurrent(False,False,0)
If Err &lt;&gt; 0 Then Call ThrowScriptError(EVENTNO_REMOVEMESSAGE_ERROR,EVENT_LEVEL_WARNING,"Test message was delivered successfully but could not be removed.",true)
Exit Do
Else
Set Message = Queue.PeekNext(False,False,1000)
End If
Loop

If MessageFound = False Then Call ThrowScriptError(EVENTNO_REMOVEMESSAGE_ERROR,EVENT_LEVEL_WARNING,"Test message was delivered successfully but could not be located in order to be removed.",true)

End Sub


Function CompareId(Id1,Id2)
Dim i
CompareId = True
For i = 1 To 20
If Midb(Id1, i, 1) &lt;&gt; Midb(Id2, i, 1) Then
CompareId = False
End If
Next

End Function

Sub LogDetail(EventNo,Message)

Message = VbCrLf &amp; "Calling MP Element ID: $MPElement$" &amp; vbcrlf &amp; Message
If bLogDetail = True Then
Call oAPI.LogScriptEvent(SCRIPT_NAME,EventNo,EVENT_LEVEL_INFO,Message)
End If

End Sub


Sub ThrowScriptError(EventNo,Severity,Message,Abort)

sMessage = VbCrLf &amp; sMessage &amp; VbCrLf &amp; _
Err.Description
Call oAPI.LogScriptEvent(SCRIPT_NAME,EventNo,Severity,Message)
If Abort = True Then WScript.Quit

End Sub</Script></ScriptBody>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DS"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
</DataSourceModuleType>