Search code examples
javaspringwebsocketstompjs

PathVariables in Spring WebSockets @SubscribeMapping not working


I am trying to something similar to this "Path variables in Spring WebSockets @SendTo mapping" But I want to send a table name as additional information to @SubscribeMapping("/topic/data"). "tablename" can be anything based on my need(what I want to set), it should concatenate @SubscribeMapping("/topic/data/{tablename}") and on the server side, I would like to access the tablename to get the data from the database. I have tried the solution mentioned in the above post lien @DestinationVariable but I think I am missing something.


Solution

  • on the server side :

     @SubscribeMapping("/getviewschema/{tablename}")
     public JSONObject getViewSchema(@DestinationVariable String tablename) throws Exception
     {
         DataManager manager = new DataManager();
         return manager.getViewJSONSchema(tablename);
     }
    

    On the client side

    socket.stomp.subscribe("/app/getviewschema/"+service.tablename,function(data) 
    {
            listenerview.notify(JSON.parse(data.body));
    });