Search code examples
rabbitmqamqp

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


I have connected 4 browsers with RabbitMQ connection. Now i want to send event broadcasting to particular browser. is it possible?

I am sending event to all browsers by following code

 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);
      });    
  };

How i can send request to particular browser/user ? is it possible to brodcast event to single browser ?


Solution

  • You can send event to particular browser/a particular tab in browser by changing subscribe call from :

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

    to

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

    where browserId would be a uniqueId to the tab in the browser and the server would push the result on the exchange with this browserId appended in the routing Key.

    Currently you are using a commonId (testMessage) , and why all the browsers have subsribed on exchange with this routing key, thus all are recieving the message.