I have a Spring Boot MVC app that connects to an external ActiveMQ Artemis server. The app has a notification module that receives notifications from certain services when some events occur. Since this is multi-page app every time an user opens a page a new STOMP connection is created.
Is there a way to retain the session and a reuse it on all pages? This is the client's code that is used to connect.
// Start listening to incoming notifications.
function startListening() {
const importSocket = new SockJS("/stomp/user");
const notificationStompClient = Stomp.over(importSocket);
notificationStompClient.connect({}, (frame) => {
console.log('Connected to ' + frame);
subscribeToNotifications(notificationStompClient);
}, (message) => {
console.log(message);
if (message instanceof Object) {
const body = JSON.parse(message.body);
if (body.statusCode === 401) retryNotificationListener = false;
} else if (message.includes('Whoops! Lost connection to') && retryNotificationListener)
setTimeout(() => startListening(), 15000);
});
}