Closed xzzh999 closed 6 months ago
Looks like something happened to your subscription? Check that you didn't exit your iterator with some exception
import {connect} from "nats";
const nc = await connect({servers: ["demo.nats.io"]});
const sub = nc.subscribe("helloworld");
(async () => {
for await(const m of sub) {
console.log(m.subject, m.string());
}
})();
let i = 0;
setInterval(() => {
nc.publish("helloworld", `${i++}`);
}, 250);
Reopen if you have better information. As it is from that stack, the client is simply pushing a message into the subscription - something else is trying to clone something, but that is not part of the code base that I can see.
Note that you can only run nats code from the app side (node.js).
@aricart thanks u reply
Note that you can only run nats code from the app side (node.js).
yes, i known, and it is. i use electron and call node.js interface through electron-preload.js bridge.
i dont use for await(const m of sub) { ... }
to recv subscribe msg, but use callback like this:
Client.prototype.subscribeMsg = async function(sub, callback) {
if(!this.isConnValid()) {
return
}
console.log("subscribe: ", sub)
this.nc.subscribe(sub, {callback: (err, msg)=> {
callback(err, msg)
}})
}
and when i change to this as u code above:
Client.prototype.subscribeMsg = async function(sub, callback) {
if(!this.isConnValid()) {
return
}
console.log("subscribe: ", sub)
const subObj = this.nc.subscribe(sub);
(async () => {
for await(const m of subObj) {
console.log(m);
callback('', this.codec.decode(m.data))
}
})();
everything works fine, no any errors, why callback not working?
I see now, msg param in callback in node.js can't clone to the randering js 's context, thank u again.
Observed behavior
code:
a single client, when first connect ok(
noEcho
flag not set ), then subscribetest1
, then call pubMsg totest1
got error:but if use nats.ws is ok
Expected behavior
pushlish ok and send msg to self ok
Server and client version
server:
2.10.12
git [121169ea] client:2.26.0
Host environment
win 10 x64
Steps to reproduce
every time comes up after connect, subscribe then publish