发送 HL7 消息后何时关闭并重新打开套接字
我正在尝试打开与 HL7 服务器的基本连接,在其中发送请求并获取 ACK 响应。这将持续进行。
- 如果连续这样做,我什么时候关闭套接字?在这种情况下,我是否正确实现了这一点?
- 如果我关闭套接字,如何再次打开它? ConnectionHub 的 javadoc 指示如下:
attach(java.lang.String host, int port, Parser parser,
java.lang.Class<? extends LowerLayerProtocol> llpClass)
返回给定地址的连接,必要时打开此连接。
然而,在现实生活中,如果连接已经关闭,它就不会打开新的连接。
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();
结果: 第一遍完美完成,发送了请求并收到了 ACK。对此方法的任何后续调用都会在客户端导致“java.net.SocketException:Socket已关闭”。 如果我删除 connection.close()
调用,那么它将在一定时间内正常运行,然后套接字将自行关闭。
I am trying to open a basic connection to an HL7 server where I send a request and get the ACK response. This will be done continuously.
- If this is being done continuously, when do I close the socket? Am I implementing this correctly, in this case?
- If I close the socket, how do I open it again? The javadocs for ConnectionHub indicates the following:
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. 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您通过 HL7 2.X 进行通信,套接字上的预期行为是永远断开连接 - 您分配连接并保持套接字处于活动状态。换句话说,HL7 应用程序不像像 Web 浏览器那样,根据需要进行连接并在完成后断开连接。相反,两端都会努力保持套接字持续连接。如果您断开连接,大多数应用程序都会感到恼火。此外,大多数集成引擎都会发出警报,如果您断开连接时间过长,这些警报就会触发。
连接套接字后,您需要使用 HL7 最低下层协议(MLLP 或 MLP)来传送 HL7 2.X 内容。如果您正在发送数据,则应在发送下一条消息之前等待 HL7 确认。如果您正在接收数据,您应该生成 HL7 Ack。
参考文献:
MLP - http://www .hl7standards.com/blog/2007/05/02/hl7-mlp-minimum-layer-protocol-defined
确认 - http://www.corepointhealth.com/resource-center/hl7-resources/hl7-acknowledgement
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. Said another way, an HL7 application does not act like a web browser wherein it connects as needed and disconnects when done. 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. If you are sending data, you should wait for an HL7 Acknowledgment before you send the next message. If you are receiving data, you should generate the HL7 Ack.
References:
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