How can you check the status of a message sent using Stompjs?

I have been working on a chat application using Spring Boot Websocket, STOMP, and stompjs. Below is a snippet of my JavaScript code:

<script src="https://cdnjs.cloudflare.com/ajax/libs/sockjs-client/1.1.4/sockjs.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/stomp.js/2.3.3/stomp.min.js"></script>
<script>
    //some code

    //send message
    stompClient.send("/app/chat.sendMessage", {}, JSON.stringify(chatMessage));
</script>

Here is the backend code:

@MessageMapping("/chat.sendMessage")
public MessageDTO sendMessage(@Payload MessageDTO chatMessage) {
    //HERE
    if(!validatorService.validate(chatMessage)) {
        throw new RuntimeException("invalid");
    }
    messagingTemplate.convertAndSend("/topic/public", chatMessage);
    return chatMessage;
}

In the code snippet, you can observe that I am returning the message. Is there a way in the JavaScript side to receive this object, maybe something like this:

stompClient.send("/app/chat.sendMessage", {}, JSON.stringify(chatMessage), callback);

Answer №1

When a STOMP client sends a MESSAGE frame, it typically does not receive a response from the broker. However, there is a possibility of receiving a RECEIPT frame if the MESSAGE frame contains the receipt header. Since you have not set this header, do not expect a response from the broker.

If you wish to receive a specific application response, you will need to set up a subscriber in your JavaScript app. The server-side app can then send a message to the designated consumer. This follows the conventional request/reply messaging pattern.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for storing headers in NODE.JS?

Recently started learning NODE.JS Looking for some guidance. When I try to execute the command below: npm install --save express-handlebars I encounter the following error message: + <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cf ...

javascript utilizing the canvas feature to resize and add graphics to an image

Is it possible to leverage Canvas for drawing over images that have been downloaded by users, all while adjusting the scale? For instance: User uploads an image Starts drawing on the image Zooms out and continues adding more drawings All modifications ...

Creating a singular and distinctive string by combining two keywords

Is it possible to create a single distinct string by combining two keywords regardless of the order in which they are entered? EDIT: The keywords in question are numerical rather than alphabetical characters. The following example is merely for explanator ...

Exploring JS Pattern Matching across Two Distinct Data Sources

In my database, I have two tables (and more can be added in the future) with rows structured like this: <table> <tr> <th>name</th> <th>salary</th> </tr> <tr> <td>a</td> &l ...

Implementing AngularJS within a standalone system devoid of internet connectivity

Hello there! I am interested in creating a single page web application for an embedded system that won't have access to the internet. This means I need to develop it without relying on external sources for functionality. Although I prefer AngularJS, ...

Indeed, verification of an array - values are mandatory only when the array exceeds a length of 1

In my form, each row contains 2 dropdowns and I have the ability to dynamically add or remove rows except for the first one. My goal is to allow form submission only if there is one pre-rendered empty row, otherwise the form should not be able to submit if ...

When the jQuery keyup event is triggered, the "function" will be incremented to 0

There are three input fields to search a JSON tree. When all three fields are filled correctly, the data from the next level of the JSON tree is retrieved. A number is incremented through the keyup event to access the next data of the JSON tree. However, ...

Learn how to use jQuery to load a text file containing arrays and then format them as

I'm attempting to load a .txt file containing multidimensional arrays using AJAX, and then sort through the data to display it on my website. However, I'm facing an issue where the data is only returning as plain text, even after trying to use JS ...

Tips for positioning dynamic high charts in a bootstrap row

I have implemented HighCharts for displaying charts on my website. Specifically, I am utilizing the chart type solidgauge. The charts are dynamic and I am looking to arrange them horizontally across the page. My goal is to align the charts in a layout sim ...

Angular log out function to automatically close pop-up windows

Within my application, there is a page where users can open a popup window. When the user clicks on logout, it should close the popup window. To achieve this, I have used a static variable to store the popup window reference in the Global.ts class. public ...

Encountering the error: "org.openqa.selenium.SessionNotCreatedException"

I encountered an issue while trying to run scripts on a grid setup. When executing the scripts, I received an exception: org.openqa.selenium.SessionNotCreatedException. Below is a simplified code snippet to replicate the problem: public class Gridtes ...

Whenever the page is refreshed, the vertical menu bar with an accordion feature hides the sub

I have designed a vertical accordion menu bar following the example at http://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_accordion_symbol However, I am encountering an issue where clicking on a button to display a submenu causes the page to refr ...

Assign a class to an element depending on the date

I need to customize a span element in my HTML code like this. html <span class="tribe-event-date-start">September 5 @ 7:00 pm</span> My objective is to identify that specific element based on its date and then apply a class to its parent co ...

What steps should be taken for the authentication process when using Active Directory (with LDAP) with an AngularJS/JavaScript frontend?

Currently, I am tackling a project that involves authenticating users in an application using their Windows credentials. The frontend is built with AngularJS and the backend with Java. After conducting extensive research, I came to the realization that it ...

What exactly does the context parameter represent in the createEmbeddedView() method in Angular?

I am curious about the role of the context parameter in the createEmbeddedView() method within Angular. The official Angular documentation does not provide clear information on this aspect. For instance, I came across a piece of code where the developer i ...

Photos failing to load in the image slider

Although it may seem intimidating, a large portion of the code is repetitive. Experiment by clicking on the red buttons. <body> <ul id="carousel" class="carousel"> <button id="moveSlideLeft" class="moveSlide moveSlideLeft"></button& ...

Tips for transmitting a batch of resources with Restangular?

Suppose I need to make a DELETE request to delete multiple products from the resource /products. The complete request should be sent to this URI: /products/ids=1&ids=2&ids=3 What is the method to send a request like this using Restangular? The c ...

What is the impact of sending a JavaScript request to a Rails method every 15 seconds in terms of efficiency?

I have a method that scans for notifications and initiates a js.erb in response. Here is the JavaScript code triggering this method: setInterval(function () { $.ajax({ url: "http://localhost:3000/checkNotification", type: "GET" }); }, 15000); ...

Hiding the address bar in Internet Explorer using Selenium

I am struggling to hide the address bar using Selenium Although I have researched Selenium's capabilities with IE, I cannot seem to find the specific one I need I am aiming to open an IE window without the address bar using Selenium integrated with ...

The Challenge of Refreshing Static Site Generation in NextJS Version 13

I've encountered a problem with updating data on a basic data page. The situation is simple: there's a page that shows category data and another page that allows editing of the same data. After making edits and returning to the list page, I expec ...