使用没有 Socket.IO 的 RabbitMQ Web STOMP 插件将事件发送到特定 browser/user

Send event to particular browser/user using RabbitMQ Web STOMP plugin without Socket.IO

我已经用 RabbitMQ 连接了 4 个浏览器。现在我想将事件广播发送到特定的浏览器。可能吗?

我正在通过以下代码向所有浏览器发送事件

 function test(){
      data = $('#msg').val();
      client.send('/topic/testMessage', {"content-type":"text/plain"}, data);  
      // exchange - routingkey    /temp-queue, /exchange, /topic, /queue, /amq/queue, /reply-queue/ 
  }
  var on_connect = function(x) { 
      id = client.subscribe("/topic/testMessage", function(d) {
           print_first(d.body);
      });    
  };

如何向特定的 browser/user 发送请求?是否可以将事件广播到单个浏览器?

您可以将事件发送到浏览器中的特定 browser/a 特定选项卡,方法是将订阅调用从 :

更改为
client.subscribe("/topic/testMessage");

client.subscribe("/topic/testMessage" + browserId); 

其中 browserId 将是浏览器中选项卡的唯一 ID,服务器会将结果推送到交换中,并将此 browserId 附加在路由密钥中。

当前您使用的是 commonId (testMessage) ,以及为什么所有浏览器都订阅了此路由密钥的交换,因此所有浏览器都收到了消息。