question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

A problem with nats client

See original GitHub issue

I’m new on nats, Today, I’ve installed nats client on node.js but cannot publish a message, so, I’m getting weird error. How can I fix this error?

My code:

const nc = require('nats').connect({'servers': ['nats://127.0.0.1:4222']});

nc.publish('foo', 'Hello World!');
Error:
TypeError: nc.publish is not a function

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
derekcollisoncommented, Jun 19, 2022

Maybe look here.

https://github.com/nats-io/nats.js/blob/main/README.md

Also my guess is you need to await the connection.

// to create a connection to a nats-server:
const nc = await connect({ servers: "demo.nats.io" });
0reactions
aricartcommented, Jun 27, 2022

Also - there are a couple of issues with the code above. Your code is publishing a message before the subscription is registered, so your two publishes will be received by the server before the subscription is registered, so your subscription will not get the messages.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem with indefinite reconnect · Issue #325 · nats-io/nats.c
Hello. I've asked you a question some time ago about slow consumers and the reason nats client can be disconnected from server.
Read more >
io.nats.client (jnats 1.0 API) - javadoc.io
If NATS detects a serious problem with a Connection object, it informs the Connection object's ExceptionHandler , if one has been registered.
Read more >
NATS streaming reconnecting to a subscription - Google Groups
The problem I'm trying to solve is for a client to reconnect after some communication failure without missing any messages. A MsgProto contains...
Read more >
Slow Consumers - NATS Docs
Most client libraries will notify the application that there is a SlowConsumer error and discard messages. Receiving and dropping messages from the server...
Read more >
Java Nats Client: Incomprehensible error message "Subject ...
It comes from io.nats.jnats version 2.8 (nats.client.impl.NatsConnection # deliverReply). But we don't notice any problem in our system.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found