简体   繁体   中英

Spring Stomp sockjs Notification queue websocket

I have a problem: i have created a notification system with spring boot, stomp, sockjs. I have a server Java and a javascript client. I have to send some notification from server to clients but: when a client is online, i send him the notification --> it works! (I use stomp and sockjs) When a client is offline i have to save the notification and i'll send him the notification saved when he will return online..Any suggestion about?? How can i do that? I have read something about ActiveMQ, but where can i find some accurate tutorial? Thank you in advance

post your code, configs... you can do that by posting notifications to a destination (topic with durable subscription if you have multiple clients for the same notification type or a queue if you have a notification for every client) and when js client connects to that destination he receive them.

You can work with websockets like this https://github.com/apache/activemq/tree/master/activemq-web-demo/src/main/webapp/websocket

https://github.com/jmesnil/stomp-websocket/blob/master/example/chat/index.html

http://activemq.apache.org/websockets.html

There are many libs and examples https://github.com/krukow/stomple/blob/master/example/transactional-chat.html

ActiveMQ Extensions to STOMP You can add custom headers to STOMP commands to configure the ActiveMQ protocol. Here are some examples:

CONNECT client-id string Specifies the JMS clientID which is used in combination with the activemq.subcriptionName to denote a durable subscriber.

http://activemq.apache.org/stomp.html

var connect = function () {
   var socket = new SockJS( webSocketUrl );
   stompClient = Stomp.over( socket );

   stompClient.connect( {"client-id": "my-client-id"},, function ( frame ) {

      console.log( 'Connected: ' + frame );

      stompClient.subscribe( topic, function ( message ) {
        .....
        .....
      }, {"activemq.subscriptionName": "my-client-id"});
   }, function(frame) {
        console.log("Web socket disconnected");
   });
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM