Failover Solution
Contents
One interesting scenario we came across with a client was this one they had third party EHR systems sending messages which could sometimes be incorrect. They would want to send a negative acknowledgment instead of forwarding the messages to their pharmacy system.
So the algorithm to follow was:
- Get the message.
- Send it to a web service to validate and in some case modify the message.
- If it was bad send back a negative ACK, this would be rendered inside the EHR systems allowing the end user or IT team to resolve the problem.
- If good, send it to the Pharmacy System, get the ACK and then send that back to the EHR system (since it could be negative).
The problem is what to do when the Pharmacy system is down. Obviously the NACK mechanism cannot be maintained but data still needs to flow.
So here’s a failover solution. The solution works by having one channel set up with LLP–>To Channel. The above script goes into the LLP Translator script. A second channel is set up with LLP listener –> LLP client which just acts as a queue when the pharmacy system is not able to receive the messages.
require('llp') function main(Data) local Success = pcall(SendMessage, Data) if not Success then SendMessageToQueue(Data) ack.send(ack.generate(Data)) end end function SendMessage(Data) -- optionally validate data here - if message is bad send NACK local C = llp.connect{host='localhost', port=5145, live=true, timeout=1} C:send(Data) local A = C:recv() C:close() ack.send(A) end function SendMessageToQueue(Data) local C = llp.connect{host='localhost', port=5362, live=true} C:send(Data) local A = C:recv() C:close() end
Continue: Suppressing ACKs altogether