TypeError: Cannot read property 'publish' of undefined
See original GitHub issuewhile running my producer.js I get the following error -> command : node stomjs/producer.js response: /home/dibyajyoti/Desktop/Feed/node_modules/@stomp/stompjs/bundles/stomp.umd.js:506 this._stompHandler.publish(params); ^
TypeError: Cannot read property ‘publish’ of #undefined at Client…/src/client.ts.Client.publish (/home/dibyajyoti/Desktop/Feed/node_modules/@stomp/stompjs/bundles/stomp.umd.js:506:28) at Object.<anonymous> (/home/dibyajyoti/Desktop/Feed/stomjs/producer.js:43:8) at Module._compile (internal/modules/cjs/loader.js:689:30) at Object.Module._extensions…js (internal/modules/cjs/loader.js:700:10) at Module.load (internal/modules/cjs/loader.js:599:32) at tryModuleLoad #(internal/modules/cjs/loader.js:538:12) at Function.Module._load (internal/modules/cjs/loader.js:530:3) at Function.Module.runMain (internal/modules/cjs/loader.js:742:12) at startup (internal/bootstrap/node.js:283:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
I’m using it with activemq, it’s getting connected but throwing error while sending a message! my stomp configuration is:
`global.WebSocket = require(“ws”);
const Stomp = require(“@stomp/stompjs”);
if (typeof TextEncoder !== “function”) { const TextEncodingPolyfill = require(“util”); TextEncoder = TextEncodingPolyfill.TextEncoder; TextDecoder = TextEncodingPolyfill.TextDecoder; }
const stompConfig = { brokerURL: “ws://localhost:61614/ws”, connectHeaders: { login: “username”, passcode: “password” }, debug: function(message) { console.log(message); }, onWebSocketClose: function(message) { console.log("Reason: ", message.reason); }, onWebSocketError: function() { console.log(“Web socket error”); }, onConnect: function(frame) { console.log(“Client connected to”, frame.headers.server); }, onDisconnect: function() { console.log(“Client disconnected”); }, onStompError: function(frame) { console.log("Broker reported error: " + frame.headers[“message”]); console.log("Additional details: " + frame.body); }, reconnectDelay: 5000, heartbeatIncoming: 4000, heartbeatOutgoing: 4000 };
const client = new Stomp.Client(stompConfig); client.activate(); client.publish({ destination: “/queue/test”, headers: { priority: 9 }, body: “Hello, STOMP” });`
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (5 by maintainers)
There is a delay between calling
client.activate
and the actual connection getting established. You have two options:onConnect
. However,onConnect
gets called every time a connection is established (like a reconnect after an error).publish
.There is wrapper of this library - https://github.com/stomp-js/rx-stomp - that uses
rxjs
. That wrapper supports local queuing of messages if the underlying connection is not there.Thanks for the replies, for now I’ve switched to node-stomp and it’s working fine for my usage. For my application requirement, stomp-js is not serving my purpose!