简体   繁体   English

何时关闭并在HL7消息发送后重新打开套接字

[英]when to close and reopen socket after HL7 message sent

I am trying to open a basic connection to an HL7 server where I send a request and get the ACK response. 我正在尝试打开一个HL7服务器的基本连接,我发送请求并获得ACK响应。 This will be done continuously. 这将不断完成。

  1. If this is being done continuously, when do I close the socket? 如果这是连续进行的,我什么时候关闭插座? Am I implementing this correctly, in this case? 在这种情况下,我是否正确实现了这一点?
  2. If I close the socket, how do I open it again? 如果我关闭插座,我该如何再次打开它? The javadocs for ConnectionHub indicates the following: ConnectionHub的javadoc表示以下内容:
attach(java.lang.String host, int port, Parser parser, 
       java.lang.Class<? extends LowerLayerProtocol> llpClass) 

Returns a Connection to the given address, opening this Connection if necessary. 返回给定地址的连接,必要时打开此连接。

However, in real life, it will not open a new connection if it was already closed. 但是,在现实生活中,如果已经关闭,它将不会打开新连接。

Patient patient = appt.getPatient();
Parser parser = new GenericParser();
Message hl7msg = parser.parse(wlp.getORMString(appt));

//Connect to listening servers
ConnectionHub connectionHub = ConnectionHub.getInstance();
// A connection object represents a socket attached to an HL7 server
Connection connection = connectionHub.attach(serverIP, serverPort, 
                            new PipeParser(), MinLowerLayerProtocol.class);
if (!connection.isOpen()) {
   System.out.println("CONNNECTION is CLOSED");
   connection = connectionHub.attach(serverIP, serverPort, new PipeParser(),         
                                     MinLowerLayerProtocol.class);
  if (!connection.isOpen()) {
    System.out.println("CONNNECTION is still CLOSED");
  }
}
Initiator initiator = connection.getInitiator();
Message response = initiator.sendAndReceive(hl7msg);

String responseString = parser.encode(response);
System.out.println("Received response:\n" + responseString);
connection.close();

Result: The first pass goes through perfectly, with request sent and ACK received. 结果:第一次传递完美,发送请求并收到ACK。 Any subsequent call to this method results in java.net.SocketException: Socket closed " on the client side. If I remove the connection.close() call, then it will run fine for a certain amount of time then the socket will close itself. 对此方法的任何后续调用都会导致java.net.SocketException: Socket closed在客户端java.net.SocketException: Socket closed 。如果我删除了connection.close()调用,那么它将运行一段时间,然后套接字将自行关闭。

If you are communicating via HL7 2.X, the expected behavior on the socket is to never disconnect -- you allocate the connection and keep the socket active. 如果您通过HL7 2.X进行通信,则套接字上的预期行为永远不会断开 - 您分配连接并保持套接字处于活动状态。 Said another way, an HL7 application does not act like a web browser wherein it connects as needed and disconnects when done. 换句话说,一个HL7应用程序不会像Web浏览器,其中它连接,根据需要和断开完成时。 Rather, both ends work to keep the socket continuously connected. 相反,两端都可以保持插座连续连接。 Most applications will be annoyed if you disconnect. 如果断开连接,大多数应用程序都会生气。 Further, most integration engines have alerts that will fire if you are disconnected for too long. 此外,如果长时间断开连接,大多数集成引擎都会发出警报。

Once the socket is connected, you need to use the HL7 Minimum Lower Layer Protocol (MLLP or MLP) to communicate the HL7 2.X content. 连接套接字后,需要使用HL7最小下层协议(MLLP或MLP)来传送HL7 2.X内容。 If you are sending data, you should wait for an HL7 Acknowledgment before you send the next message. 如果要发送数据,则应在发送下一条消息之前等待HL7确认。 If you are receiving data, you should generate the HL7 Ack. 如果您正在接收数据,则应生成HL7 Ack。

References: 参考文献:

MLP - http://www.hl7standards.com/blog/2007/05/02/hl7-mlp-minimum-layer-protocol-defined MLP - http://www.hl7standards.com/blog/2007/05/02/hl7-mlp-minimum-layer-protocol-defined

Acks - http://www.corepointhealth.com/resource-center/hl7-resources/hl7-acknowledgement Acks - http://www.corepointhealth.com/resource-center/hl7-resources/hl7-acknowledgement

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM