How to repeat failed ACK without hanging a channel

Introduction

This is an expansion of example from page Custom ACK Example combined with example from page Raising and Catching Errors, spiced with ‘retry’ module applied ‘as is’.

People asked several times how to combine these all together, so hopefully this page will save few help emails.

If you have any questions please contact us at support@interfaceware.com.

Task [top]

How to repeat failed ACK without hanging a channel.

Implementation [top]

This is not a trick, but expansion of example from page Custom ACK Example combined with example from page Raising and Catching Errors, spiced with ‘retry’ module applied ‘as is’.

Note: This is the same example Retrying a Custom ACK, but with a some extra explanatory comments added to the code. The code is also in our repository.

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!"

   local s = Ack:S()

   local Success, Err = pcall(retry.call,
         { func = ack.send, arg1 = s, retry = 10, pause = 2} )

   if not Success then
      print("Skipping error: "..Err) 
   end

end

More information [top]