[英]Is it possible to identify web-socket request on receive?
I have two queries that are sent one after the other. 我有两个查询,一个接一个地发送。 If I use
send
method, than I get the response in onmessage
and I need to know which response it was - from the first query or from the second. 如果我使用
send
方法,那么我会onmessage
的响应,我需要知道它是哪个响应-从第一个查询或从第二个查询。 Is it possible? 可能吗?
You should add a correlation id to each request, and return that id with the response, that way the client would know which response is associated with which request. 您应该为每个请求添加一个关联ID,并在响应中返回该ID,这样客户端就可以知道哪个响应与哪个请求相关联。
Since it is a client concern, the id can be a simple incremental integer, does not need to be a GUID or unique number. 由于是客户问题,所以id可以是简单的增量整数,而不必是GUID或唯一编号。 The server just have to attach the request id to the response, does not need to do anything with it.
服务器只需要将请求ID附加到响应即可,而无需执行任何操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.