Skip to content

boghy933/spring-stomp-sockjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

How to test

  1. Open url http://localhost:8080/websocket
  2. Open browser developer tools and go to console
  3. Copy and paste the code for stomp from cdn => https://cdnjs.cloudflare.com/ajax/libs/stomp.js/2.3.3/stomp.min.js inside the console
  4. Copy and paste the code for sockjs cdn => https://cdn.jsdelivr.net/npm/sockjs-client@1/dist/sockjs.min.js inside the console
  5. Copy the script to connect
  6. run "connectRome()" inside console
  7. Check for new messages in console
  8. For London do the same thing in a new tab

Script

function connectRome() {
    var socket = new SockJS('http://localhost:8080/websocket');
    stompClient = Stomp.over(socket);
    stompClient.connect({}, function (frame) {
        stompClient.subscribe('/topic/Rome', function (greeting) {
            console.log("Received message: " . greeting)
        });
    });
}

function connectLondon() {
    var socket = new SockJS('http://localhost:8080/websocket');
    stompClient = Stomp.over(socket);
    stompClient.connect({}, function (frame) {
        stompClient.subscribe('/topic/London', function (greeting) {
            console.log("Received message: " . greeting)
        });
    });
}

About

Demo project with spring stomp and sockjs

Topics

Resources

Stars

Watchers

Forks

Languages