Retry a Custom ACK

Added by iNTERFACEWARE

Retries a a custom ACK using the retry.lua module

Source Code
local retry = require 'retry'
 
-- main() is given the original HL7 message.
function main(Data)
 
   local Msg = hl7.parse{vmd='ack.vmd', data=Data}
   local Ack = hl7.message{vmd='ack.vmd', name='Ack'}
 
   Ack.MSH[3][1] = Msg.MSH[5][1]
   Ack.MSH[4][1] = Msg.MSH[6][1]
   Ack.MSH[5][1] = Msg.MSH[3][1]
   Ack.MSH[6][1] = Msg.MSH[4][1]
   Ack.MSH[10] = Msg.MSH[10]
   Ack.MSH[9][1] = 'ACK'
   Ack.MSH[11][1] = 'P'
   Ack.MSH[12][1] = '2.6.1'
   Ack.MSH[7][1] = os.date('%Y%m%d%H%M%S')
 
   Ack.MSA[1] = 'AA'
   Ack.MSA[2] = Msg.MSH[10]
   Ack.MSA[3] = "Everything was okay dokay!"
 
   -- after retries tried retry.call() raises an error which will stop the channel 
   -- this means no more messages will be processed until you restart the channel
   local R1, R2 = retry.call{func = ack.send, arg1 = Ack:S(), retry = 10, pause = 2} 
 
   -- if you want to continue processing further messages then you can
   -- use pcall() to trap the error and prevent the channel from stopping
   local Success, R1, R2 = pcall(retry.call,
      { func = ack.send, arg1 = Ack:S(), retry = 10, pause = 2} )
 
   if not Success then
      local Err = R1
      iguana.logInfo(Err)
      -- do some other error processing if desired
   end
end
Description
Retries a a custom ACK using the retry.lua module