Angular2 with Stomp.js

天大地大妈咪最大 提交于 2019-12-08 09:00:34

If you are using new version of angular2 CLI https://cli.angular.io/

I would recommend to use STOMP-Over-WebSocket Service for angular 2

Install this npm packages

npm i --save stompjs
npm i --save sockjs-client
npm i --save ng2-stomp-service

In typings.d.ts

Add stompjs and sockjs-client module declaration

declare module 'stompjs';
declare module 'sockjs-client';

In app.module.ts

import { StompService } from 'ng2-stomp-service';

@NgModule({
  ...
  providers: [StompService]
})

In app.components.ts

import { StompService } from 'ng2-stomp-service';

private wsConf = {
  host:'test.com'
}

constructor(stomp: StompService) {

  stomp.configure(this.wsConf);

  stomp.startConnect().then(() => {
    console.log('connected');
  });


}

source https://github.com/devsullo/ng2-STOMP-Over-WebSocket

For a proper Angular2/4/5 type StompService using Observables please refer to https://github.com/stomp-js/ng2-stompjs. This library exposes entire functionality using rxjs Observables.

It has been reported to work with Spring over WebSockets with and without security.

There are sample apps for Angular2, Angular4 and Agular5 as well.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!