0

I have a spring boot application that will have publish to user defined destination channels as such:

@Autowired
private SimpMessagingTemplate template;

public void send() {
   //..
   String uniqueId = "123";
   this.template.convertAndSendToUser(uniqueId, "/event", "Hello");
}

Then a stomp over SockJS client can subscribe to it and receive the message. Suppose I have a stomp endpoint registered in my spring application called "/data"

var ws = new SockJS("/data");
var client = Stomp.over(ws);
var connect_fallback = function() {
   client.subscribe("/user/123/event", sub_callback);
};

var sub_callback = function(msg) {
    alert(msg);
};

client.connect('','', connect_callback);

Actually there will be more than one user client subscribing to the same distinct user destination, so each publish/subscribe channel is not one to one and I am only doing it this way since spring's concept of "/topic" have to be defined programmatically and "/queues" can only be consumed by one user. How do I know when a user destination no longer has any subscribers? And how do I delete a user destination?

ron
  • 239
  • 3
  • 18
  • which message broker are you using? – Karthik Feb 24 '16 at 21:01
  • just the default simple broker provided by spring, now im thinking if i need to embed a full featured broker such as activemq to support this. – ron Feb 25 '16 at 03:01

2 Answers2

0
@SendToUser('/queue/dest')
public String send() {
   //..
   String uniqueId = "123";
   return "hello";
}

On the Client you would subscribe to '/user/queue/dest'

http://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html#websocket-stomp-user-destination

user3420988
  • 487
  • 2
  • 5
  • this does not answer the question, as noted the question i demonstrated that i already know how to do that, thanks for noticing the question but please don't skip over the last bit. – ron Feb 26 '16 at 00:45
0

After adding a channel interceptor and setting breakpoints within a code segment running in debug mode in eclipse, I found that there is a collection of websocket session and destination mappings in the registry objects that are held by the message handlers, which in turn can be seen stored inside the message channel object. I found this for the topics though not sure about purely user destination method.

However, Spring does not leave the api open for me to just call a function to get a list of all subscribers to every topic, at least not without passing in the message. Everything else that would have been helpful is set private so cannot be programmatically accessed. This is not helpful as i would like to trigger an action upon unsubscribe or disconnect of a client ONLY when the topic that is being unsubscribed/disconnected from does not have other listening clients left.

Now looking at embedding full featured broker such as ActiveMQ to see if it can potentially solve my problem

ron
  • 239
  • 3
  • 18