Closed bdushimi closed 4 months ago
The connect you have is for nats, which possibly is getting reexported there - can you try:
const sc = require('node-nats-streaming').connect('tickets', uniqueClientId)
Also note, that stan.js is deprecated - if you are starting new work, please use JetStream - which is built into the current nats clients.
@aricart
I tried this 👇 but I still get the same error as described above.
The connect you have is for nats, which possibly is getting reexported there - can you try:
const sc = require('node-nats-streaming').connect('tickets', uniqueClientId)
I c/p your code:
nats-streaming-server -cid tickets --store MEMORY
[27324] 2023/02/27 13:22:51.913993 [INF] STREAM: Starting nats-streaming-server[tickets] version 0.25.3
[27324] 2023/02/27 13:22:51.914060 [INF] STREAM: ServerID: kVTeghEuBH7xbHOD4MH0sy
[27324] 2023/02/27 13:22:51.914062 [INF] STREAM: Go version: go1.19.5
[27324] 2023/02/27 13:22:51.914064 [INF] STREAM: Git commit: [5cd100e]
[27324] 2023/02/27 13:22:51.915403 [INF] Starting nats-server
[27324] 2023/02/27 13:22:51.915408 [INF] Version: 2.9.11
[27324] 2023/02/27 13:22:51.915410 [INF] Git: [23ffc16]
[27324] 2023/02/27 13:22:51.915411 [INF] Name: NCNO6RLJC5HEWJXMTWNGI4IN7GB4TH7OWIHKNWSJYOF2KYRTA2KP63IW
[27324] 2023/02/27 13:22:51.915413 [INF] ID: NCNO6RLJC5HEWJXMTWNGI4IN7GB4TH7OWIHKNWSJYOF2KYRTA2KP63IW
[27324] 2023/02/27 13:22:51.915874 [INF] Listening for client connections on 0.0.0.0:4222
[27324] 2023/02/27 13:22:51.916030 [INF] Server is ready
[27324] 2023/02/27 13:22:51.944307 [INF] STREAM: Recovering the state...
[27324] 2023/02/27 13:22:51.944321 [INF] STREAM: No recovered state
[27324] 2023/02/27 13:22:51.944684 [INF] STREAM: Message store is MEMORY
[27324] 2023/02/27 13:22:51.944716 [INF] STREAM: ---------- Store Limits ----------
[27324] 2023/02/27 13:22:51.944719 [INF] STREAM: Channels: 100 *
[27324] 2023/02/27 13:22:51.944722 [INF] STREAM: --------- Channels Limits --------
[27324] 2023/02/27 13:22:51.944724 [INF] STREAM: Subscriptions: 1000 *
[27324] 2023/02/27 13:22:51.944726 [INF] STREAM: Messages : 1000000 *
[27324] 2023/02/27 13:22:51.944728 [INF] STREAM: Bytes : 976.56 MB *
[27324] 2023/02/27 13:22:51.944730 [INF] STREAM: Age : unlimited *
[27324] 2023/02/27 13:22:51.944732 [INF] STREAM: Inactivity : unlimited *
[27324] 2023/02/27 13:22:51.944734 [INF] STREAM: ----------------------------------
[27324] 2023/02/27 13:22:51.944736 [INF] STREAM: Streaming Server is ready
[27324] 2023/02/27 13:23:48.355679 [INF] STREAM: Channel "ticket:created" has been created
Note the last line, and the client:
node main.js
Listener connected to NATS
@aricart for some reasons, I do not still get it to work! I'd like to see your main.js file and package.json file. I could start from there.
The message is an error returned in response to the subscription by the server. From what I can tell that client ID is not found by the stan server - which is weird because the client is actually connected - is there as weird cluster or something going on?
Perhaps @kozlovic can tell from looking at the message?
import nats from 'node-nats-streaming';
import { randomBytes } from 'crypto';
const uniqueClientId = randomBytes(4).toString('hex');
const client = nats.connect('tickets', uniqueClientId, {
url: 'nats://localhost:4222'
})
client.on('connect', ()=>{
console.log('Listener connected to NATS');
const opts = client.subscriptionOptions();
opts.setStartWithLastReceived();
const subscription = client.subscribe('ticket:created', 'orders-service-queue-group', opts);
})
{
"name": "s_test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"node-nats-streaming": "^0.3.2"
}
}
The message is an error returned in response to the subscription by the server. From what I can tell that client ID is not found by the stan server - which is weird because the client is actually connected - is there as weird cluster or something going on?
Perhaps @kozlovic can tell from looking at the message?
@aricart No cluster actually!
I just have 1 publisher, sending messages to the channel ticket:created and it seems working fine i.e no errors. Here're the publisher codes
import nats from 'node-nats-streaming'
const client = nats.connect('tickets', 'abc', {
url: 'http://localhost:4222',
});
client.on('connect', ()=> {
console.log('Publisher connected to NATS')
const data = JSON.stringify({
id: '123',
title: 'concert',
price: 20
})
client.publish('ticket:created', data, ()=> {
console.log('Event published')
})
})
cluster is the "stan cluster" which has an unique name - the 'tickets' argument in your client.
@kozlovic Maybe you can help. I am still having the same error as described above.
I am trying to create a subscription to a channel ticket:created. A call to subscribe method just returns Error: can't find clientID.
Listener/Subscriber codes
Error logs:
Any help would be much appreciated, thanks.
FYI, Publishing messages to ticket:created channel works just fine i.e no errors.