2

I'm looking for Stomp.js or similar libs. I not found working with angular2.rc6/final example or lib. How can I reaplace Stomp.js something else? In my previously project with Angular 1.X I used Stomp.js with Sock. I'm in stuck..

UPDATE

I tried with this example application but but without effect. This example is outdated. https://github.com/sjmf/ng2-stompjs-demo

1

2 Answers 2

6

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

Sign up to request clarification or add additional context in comments.

3 Comments

This is a good solution. It works with Spring WebSocket without security. However, it does not work with Spring Security and Spring Security WebSocket.
How can we do if the application has not been created with angular CLI ?
What change with Angular 6?
3

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.