nats-io / nats.ws

WebSocket NATS
Apache License 2.0
329 stars 29 forks source link

invalid stream name - stream name cannot contain '.' #181

Closed JalilArfaoui closed 1 year ago

JalilArfaoui commented 1 year ago

I've been using requests and subscriptions successfully and I'm now trying to fetch a stream :

      const codec = JSONCodec();
      const stream = nc.jetstream();

      const msg = await stream.pull('pub.system.log.>', 'me');

      const m = codec.decode(msg.data);

      console.log('stream: ', m);

      msg.ack();

But I'm getting

Uncaught (in promise) Error: invalid stream name - stream name cannot contain '.'
    validateName nats.js:787
    validateStreamName nats.js:779
    pull nats.js:8694

And I don't understand the error since stream names usually contain dots as seen in https://github.com/nats-io/nats.deno/blob/main/jetstream.md

Same error with

      const codec = JSONCodec();
      const stream = nc.jetstream();

      const msgs = await stream.fetch('pub.system.log.>', 'me');

      const done = (async () => {
        for await (const m of msgs) {
          const json = codec.decode(m.data);
          console.log('stream', json);
          m.ack();
        }
      })();
      await done;
aricart commented 1 year ago

@JalilArfaoui the API use above is wrong, the API there wants a stream name, not a subject, and it retrieves the next message for that durable consumer, streams indeed cannot have dots.

JalilArfaoui commented 1 year ago

Yes, I got confused, reading the documentation, with the others methods that use subject like publish or pullSubscribe

It's working perfectly now.