websocket消息订阅

import SockJS from  'sockjs-client';
import Stomp from 'stompjs';

ws(url, subUrl) {
        return new Promise((resolve, reject) => {
            let socket = new SockJS(url)
            let stompClient = Stomp.over(socket)
            stompClient.connect({}, () => {
                stompClient.subscribe(subUrl, function (message) {
                    try {
                        resolve(message.body)
                    } catch (err) {
                        reject(err)
                    }
                })
            })
        })
    }

 

posted @ 2021-01-14 16:32  鱿鱼须须  阅读(1089)  评论(0编辑  收藏  举报