简体   繁体   English

在STOMP客户端心跳加速

[英]Heart-beating in STOMP client

The design of my current stomp client process is as follows: 我当前的stomp客户端进程的设计如下:

  1. Open stomp connection (sending CONNECT frame) 打开stomp连接(发送CONNECT帧)
  2. Subscribe to a feed (send a SUBSCRIBE frame) 订阅源(发送SUBSCRIBE帧)
  3. Do a loop to continually receive feed: 循环以持续接收Feed:
 while (true) { connection.begin("txt1"); StompFrame message = connection.receive(); System.out.println("message get header"+message.toString()); LOG.info(message.getBody()); connection.ack(message, "txt1"); connection.commit("txt1"); } 

My problem with this process is that I get 这个过程的问题在于我得到了

java.net.SocketTimeoutException: Read timed out
 at java.net.SocketInputStream.socketRead0(Native Method)...

and I think the cause of this is mostly because the feed I am subscribed to gives information slower on certain times (as I normally get this error when the weekend comes, holidays or evenings). 我认为造成这种情况的原因主要是因为我订阅的Feed会在某些时候提供较慢的信息(因为我通常会在周末,节假日或晚上时收到此错误)。

I have been reading up on this here and I think this would help with my problem. 我一直在这里阅读,我认为这将有助于解决我的问题。 However, I'm not so sure how to incorporate it with the current layout of my stomp client. 但是,我不太确定如何将它与我的stomp客户端的当前布局相结合。 Would I have to send a CONNECT header within Step 3? 我是否必须在步骤3中发送CONNECT标头?

I am currently using activemq to create my stomp client if that helps. 我目前正在使用activemq创建我的stomp客户端,如果这有帮助。

In the stomp spec we have: 在stomp 规范中,我们有:

Regarding the heart-beats themselves, any new data received over the network connection is an indication that the remote end is alive. 关于心跳本身,通过网络连接接收的任何新数据都表明远程端是活着的。 In a given direction, if heart-beats are expected every milliseconds: 在给定的方向上,如果每毫秒都有心跳:

  • the sender MUST send new data over the network connection at least every milliseconds 发送方必须至少每毫秒通过网络连接发送新数据
  • if the sender has no real STOMP frame to send, it MUST send a single newline byte (0x0A) 如果发送方没有要发送的真实STOMP帧,它必须发送一个换行字节(0x0A)
  • if, inside a time window of at least milliseconds, the receiver did not receive any new data, it CAN consider the connection as dead 如果在一个至少毫秒的时间窗口内,接收器没有收到任何新数据,它可以认为连接已经死了
  • because of timing inaccuracies, the receiver SHOULD be tolerant and take into account an error margin 由于时序不准确,接收器应该容忍并考虑误差范围

Would that mean my client would need to send a newline bye every n seconds? 这是否意味着我的客户需要每n秒发送一个换行符?

The stomp server you are connected to has timed out your connection due to innactivity. 您连接的stomp服务器由于无效而超时连接。

Providing the server supports Stomp version 1.1 or newer, the easiest solution for your client is to include a heart-beat instruction in the header of your CONNECT, such as "0,10000". 如果服务器支持Stomp 1.1或更高版本,则客户端最简单的解决方案是在CONNECT的标头中包含心跳指令,例如“0,10000”。 This tells the server that you cannot send heart-beats, but you want it to send one every 10 seconds. 这告诉服务器您无法发送心跳,但是您希望它每10秒发送一次。 This way you don't need to implement them, and the server will keep the connection active by sending them to you. 这样您就不需要实现它们了,服务器会通过发送给您来保持连接处于活动状态。

Of course the server will have its own requirements of the client. 当然服务器将有自己的客户端要求。 In your comment it responds to your request with "1000,0". 在您的评论中,它以“1000,0”响应您的请求。 This indicates that it will send a heart-beat every 1000 millisecs, and it expects you to send one every 0 millisecs, 0 indicating none at all. 这表明它将每1000毫秒发送一次心跳,并且它希望你每0毫秒发送一个,0表示根本没有。 So your job will be minimal. 所以你的工作将是最小的。

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

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