3

I have the following code from a very popular spring websocket demo:

   stompClient.connect({}, function(frame) {
    setConnected(true);
    console.log('Connected: ' + frame);
    stompClient.subscribe('/user/queue/greeting', function(greeting) {          
        displayQueueMessage(greeting);
    });

function sendName() {
  var name = document.getElementById('name').value;
  stompClient.send("/app/wsdemo", {}, JSON.stringify({
    'name' : name
   }));
}

On connect, we actually subscribe to to a queue and provide a callback method.

Now, imagine i have a server service for the websocket that is called getAllUsers

and lets assume i have 2 different components in my front end, usersOnGeographicMap, usersOnDataTable.

lets assume this 2 view components want to make use of the server service (getAllUsers). these 2 component each has a callback function, (one that displays the users on a geographic map, the other callback function draws them on a data table)

the problem now is that i only subscribe to a queue once, and provide him with one callback function. so how do i solve this issue?

ofcourse in ajax it will be very easy because each call is provided with a call back: -usersOnGeographicMap.getUsersAjax(callback1) -usersOnDataTable.getUsersAjax(callback2)

4

0 回答 0