I've an Angular app that successfully commnunicate with on a STOMP Websocket provided by a Springboot server. For some reasons, I need to have a mock server to be able to run Angular without the springboot server. I tried diffferents solutions but I cant get it to work. Currently, I'm using "stomp-broker-js" but as soon as the client try to connect it crash. I don't want to change the Angular code cause it works well with the real server.
Here's my mock server code:
const http = require("http");
const StompServer = require("stomp-broker-js");
const node_static = require("node-static");
const static_directory = new node_static.Server(__dirname);
const server = http.createServer((request, response) => {
console.log(request.url);
static_directory.serve(request, response);
});
const stompServer = new StompServer({
server: server,
debug: console.log,
path: "/updates",
protocol: "sockjs",
heartbeat: [2000, 2000],
});
console.log(" [*] Listening on 0.0.0.0:3000");
server.listen(3000, "localhost");
stompServer.subscribe("/echo", (msg, headers) => {
var topic = headers.destination;
console.log(`topic:${topic} messageType: ${typeof msg}`, msg, headers);
stompServer.send("/echo", headers, `Hello from server! ${msg}`);
});
Here's the log:
node MobiusStompWSMockServer.js
SockJS v0.3.24 bound to "/updates"
[*] Listening on 0.0.0.0:3000
GET /updates 1ms (unfinished)
node:events:368
throw er; // Unhandled 'error' event
^
Error: read ECONNRESET
at TCP.onStreamRead (node:internal/stream_base_commons:220:20)
Emitted 'error' event on Socket instance at:
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
errno: -4077,
code: 'ECONNRESET',
syscall: 'read'
}
And in the client side, it crash in client.js:
The network shows "connection: upgrade" and the server shows "unfinished".
For the angular part, I used "rx-stomp", exactly like indicated in https://stomp-js.github.io/guide/rx-stomp/rx-stomp-with-angular.html.
Does someone have an idea or have succesfully mock a spring boot stomp websocket?
Thanks for your help!