StompBrokerJS icon indicating copy to clipboard operation
StompBrokerJS copied to clipboard

Subscribe and publish

Open theRenard opened this issue 4 years ago • 5 comments

I can't get en event to fire when a client subscribe a topic but only when on that topic a message is received. Like if on('subscribe') acts more like on ('publish'). Is there an event that fires just when a user subscribes even if no messages are sent at all ?

I also don't really get how to create a topic with the the dot notation.

for instance, I could send to topic /one/two but not sure if I should listen to subscription to /one.two or one.two´ or /one/two`... could you be more explicit in the documentation or examples maybe ?

theRenard avatar Sep 04 '20 10:09 theRenard

+1

Caleb-Bolton avatar Apr 21 '22 22:04 Caleb-Bolton

+1, seems like there is no callback to tell that the topic has been subscribed. @4ib3r is this project being maintained? I want to implement it.

ahmed-faraz46 avatar Feb 03 '24 12:02 ahmed-faraz46

@Caleb-Bolton @theRenard wondering if you found any workarounds, I want to send some messages to the client as soon as a topic is subscribed.

ahmed-faraz46 avatar Feb 03 '24 12:02 ahmed-faraz46

Not sure 100% but I think I've moved to this https://github.com/stomp-js/stompjs

theRenard avatar Feb 03 '24 14:02 theRenard

I was finally able to achieve this using middleware

function onSubscribeMiddleware(socket, args, callNext) {
  // send something to the subscriber
  return callNext(socket, args, callNext);
}

stompServer.addMiddleware('subscribe', onSubscribeMiddleware);
stompServer.subscribe('/topic/messages/#', () => {});

ahmed-faraz46 avatar Mar 21 '24 10:03 ahmed-faraz46