Using dynamic SQL it is possible to set the source, target, new target hosts and time ranges for messages resend dynamically as is shown in the sample class method. The last parameter pResend could be used to enable/disable the resend:

ClassMethod ResendMessages(pSource = "MsgRouter", pTarget = "HL7FileOperation", pNewTarget = "FTP_Out", pTimeFrom = "2016-10-16 18:00:00.000", pTimeTo = "2016-10-16 19:00:00.000", pResend = 0)
{
Set tQuery = "select * from Ens.MessageHeader where "
Set tQuery = tQuery_" SourceConfigName="_"'"_pSource_"'"
Set tQuery = tQuery_" and TargetConfigName="_"'"_pTarget_"'"
Set tQuery = tQuery_" and TimeCreated > "_"'"_pTimeFrom_"'"
Set tQuery = tQuery_" and TimeCreated < "_"'"_pTimeTo_"'"
 
Write !, "SQL query for messages resend:", !, tQuery, !
Write !, "Messages new target: ", pNewTarget, !
Write !, "Resend messages? ", pResend, !
 
Set tRS = ##class(%ResultSet).%New("%DynamicQuery:SQL")
Set tRS.RuntimeMode = 1
Do tRS.Prepare(tQuery)
Set tSC = tRS.Execute()
Set tRowcount=0, tHL7count=0
While tRS.Next() {
Set tRowcount = tRowcount + 1
Set tClass = tRS.Data("MessageBodyClassName")
Set tId = tRS.Data("ID")
Set tHL7Id = tRS.Data("MessageBodyId")
Continue:tClass'="EnsLib.HL7.Message"
If pResend {
Set tSC = ##class(Ens.MessageHeader).ResendDuplicatedMessage(tId,,pNewTarget)
If $$$ISERR(tSC) { Do $system.OBJ.DisplayError() Quit }
Set tHL7count = tHL7count + 1
}
 }

 Write !, "Message Headers: ", tRowcount, !
 Write "Resent HL7 messages: ", tHL7count,!
}

Sample ResendMessages call:

ENSEMBLE>do ##class(Sample.Resender).ResendMessages("MsgRouter", "HL7FileOperation", "FTP_Out", "2016-10-16 18:00:00.000", "2016-10-16 19:00:00.000", 1)
 
SQL query for messages resend:
select * from Ens.MessageHeader where  SourceConfigName='MsgRouter' and TargetConfigName='HL7FileOperation' and TimeCreated > '2016-10-16 18:00:00.000' and TimeCreated < '2016-10-16 19:00:00.000'
 
Messages new target: FTP_Out
 
Resend messages? 1
 
Message Headers: 2
Resent HL7 messages: 2

 

If you need to resend a large number of messages - check the article / code snippet:

"How to resend a large number of messages in Ensemble"