Ive created a stompclient with js that can send messages to a spring boot server written in kotlin. the problem is, the publish method of the stompClient supposedly sends the payload but the server doesn't receive anything or return anything and the stompclient doesn't return any error.
Here is my stompCode :
$(document).ready(function () {
"use strict";
let stompClient = null;
let username = null;
const stompConfig = {
connectHeaders: {
login: "user",
passcode: "b7b0b48f-70a7-41ec-9be1-fde416564aef"
},
brokerURL: "ws://localhost:8080/chat",
debug: function (str) {
console.log('STOMP: ' + str);
},
reconnectDelay: 500,
// Subscriptions should be done inside onConnect as those need to reinstated when the broker reconnects
onConnect: function (frame) {
const subscription = stompClient.subscribe('/topic/greetings', (greeting) => {
showGreeting(JSON.parse(greeting.body).content);
});
}
};
stompClient = new StompJs.Client(stompConfig);
function connect(){
//will call the onConnect event on stompClient config
stompClient.activate();
username = $("#insertedName").val().trim() + " " + Math.round(Math.random() * 1000);
}
function send(){
if (!stompClient.connected) {
alert("Broker disconnected, can't send message.");
return;
}
if ($("#insertedMessage").val().trim().length > 0) {
const msg = $("#insertedMessage").val().trim()
const payLoad = {from: username, message: msg, type: 'TEXT'};
stompClient.publish({destination: '/app/hello', body: JSON.stringify({'name': $("#name").val()})
});
}
}
function disconnect(){
stompClient.deactivate();
}
});
stomp client response when i send :
STOMP: >>> SEND
destination:/app/hello
content-length:2
Tried changing the URL, tried changing waypoints, responses enabling a CORS extension, and nothing worked.
here is my spring boot config and controller :
override fun configureMessageBroker(config: MessageBrokerRegistry) {
config.setApplicationDestinationPrefixes("/app")
config.enableSimpleBroker("/topic/")
}
override fun registerStompEndpoints(registry: StompEndpointRegistry) {
registry.addEndpoint("/chat")
}
@MessageMapping("/chat")
@SendTo("/topic/greetings")
fun sendMessage(@Payload message: Message): Message {
return Message(message.from,message.message,message.type)
}