Home » Javascript » Can I make multiple connections at the same time with Stomp?

Can I make multiple connections at the same time with Stomp?

Posted by: admin November 1, 2017 Leave a comment

Questions:

I’m using ng2-stomp-service in my Angular app.

Does it make sense to establish multiple connections (not multiple subscriptions)? In the past, I’ve only seen a single connection being made, and from there we make multiple subscriptions. But now my colleague is suggesting I make three connections, and I have a different subscription to each one. The rationale (I’m told) is so that if we lose connection to one, we still have a connection for the others.

I’m not even sure how I’d code this. Presently, I have one connection. It looks like this:

       if (this.stomp.status !== 'CONNECTED') {
            this.stomp.configure(this.socketConfig);
            this.stomp.startConnect().then((frame) => {
              this.stomp.done('init');
            });

            this.stomp.after('init').then(() => {
                this.reestablishSubscriptions();
            });
        }

But it seems like if I were to make multiple connections, I would need more instances of stomp itself, like this.stomp, this.stomp2, this.stomp3, each one calling their own connect function? Or can a single this.stomp establish multiple connections?

Answers: