1.0.12 • Published 6 years ago
vue-stomp-ds v1.0.12
vue-stomp-ds
vue stomp 协议客户端需要配合http://10.168.4.20:8099/daoshu/public-architecture.git 中public-architecture/common-platform/platform/daoshu-message后端一起使用
使用帮助
下载
npm install vue-stomp-ds -S
使用
1.在main.js中引入vue-stomp-ds,例如:
import VueStomp from 'vue-stomp-ds'
Vue.use(VueStomp, 'http://localhost:9050/msg-websocket')
2.在需要引入stomp的组件中直接使用vue-stomp-ds,方法:
connectWM
参数:
- Endpoint:websocket的链接地址
- Header:链接参数
- callback:链接成功回调函数
- errorCallback: 失败回调函数
用法:
this.connetWM('http://localhost:9050/msg-websocket?userId=01', headers, this.onConnected, this.onFailed);
subscribe
参数:
- destination:订阅地址
- callback:订阅成功回调函数
- errorCallback: 订阅回调函数
用法:
this.$stompClient.subscribe('/topic/username', this.responseCallback, this.onFailed);
sendWM
参数:
- destination:发送地址
- msg:发送内容
- invokeId: 唯一编号
- callback: 发送成功回调
- timeOut: 过期时间
用法:
this.sendWM(destination, JSON.stringify(body), invokeId, this.responseCallback, 3000);
sendToUser
参数:
用法:
this.sendToUser(user, JSON.stringify(body), invokeId, this.responseCallback, 3000);
stompClient
参数:
- monitorIntervalTime:监视轮询时间设置
- stompReconnect:是否重连
- timeout: 超时回调
- reconnectTimes: 每次重试次数
- reconnectIntervalTime: 重连间隔
用法:
export default {
name: 'App',
mounted() {
},
stompClient: {
monitorIntervalTime: 1000,
stompReconnect: true,
timeout(orgCmd) {
console.log('orgCmd', orgCmd)
},
reconnectTimes: 10,
reconnectIntervalTime: 30000
}
}