N
N
Nikolai Stupak2016-06-17 11:04:40
Java
Nikolai Stupak, 2016-06-17 11:04:40

How to subscribe via websockets to a dynamic list of subscriptions in spring?

The task is as follows. API needs to be implemented. This api contains two kinds of methods:
1) normal (synchronous) methods implemented via REST requests, for example

$.ajax({
    method:'GET',
    url: "localhost:8080/api/v1/some/resource",
    data: {
        param1: value1,
        param2: value2
    }
    success: function(data) {
        // do something...
    }
});

2) subscriptions to events implemented via websocket, for example using stomp:
var socket = new SockJS('/api/stomp');
stompClient = Stomp.over(socket);
stompClient.connect({}, function(frame) {
    stompClient.subscribe('/api/v1/some/subscription', function(message){
        console.log(message);
    });
});

The server application uses Spring, respectively, I use the string implementation of Spring + WebSocket Api + Stomp.
The fact is that the architecture is such that there is not and will not be a strictly defined list of such subscriptions (because api is intended for a platform that allows you to implement various application tasks and its model is generated dynamically, respectively, the list of resources is also dynamic).

Can I somehow, using Spring, make sure that when I receive a subscription request, I determine in my handler whether there is such a subscription, and only if there is a subscription, sign the client?
Also, some parameters may be required to perform a subscription from the client. How can I best pass these parameters? Directly in the line '/api/v1/some/subscription?param1=value1¶m2=value2', or using stomp message headers?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question