README's first example does not run as desired.
See original GitHub issueThe code I run is taken from README.md Basic usage with first line modified. It is
var stan = require( 'node-nats-streaming' ).connect( 'test-cluster', 'client-123', 'nats://localhost:4222' );
stan.on( 'connect', function() {
// Simple Publisher (all publishes are async in the node version of the client)
stan.publishAsync( 'foo', 'Hello World!', function( err, guid ) {
if ( err ) {
console.log( 'publish failed: ' + err );
} else {
console.log( 'published message with guid: ' + guid );
}
} );
// Subscriber can specify how many existing messages to get.
var subscription = stan.subscribe( 'foo' );
subscription.on( 'message', function( msg ) {
console.log( 'Received a message: ' + msg.getData() );
} );
// Unsubscribe
subscription.unsubscribe();
// Close connection
stan.close();
} );
The result it produces
$ node a.js
Error
at Client.publish (/.../node_modules/nats/lib/nats.js:930:15)
at Client.request (/.../node_modules/nats/lib/nats.js:1123:10)
at Client.<anonymous> (/.../node_modules/node-nats-streaming/lib/stan.js:254:13)
at emitOne (events.js:96:13)
at Client.emit (events.js:188:7)
at Client.connectCB (/.../node_modules/nats/lib/nats.js:330:10)
at /.../node_modules/nats/lib/nats.js:755:67
at Client.processInbound (/.../node_modules/nats/lib/nats.js:725:33)
at Socket.<anonymous> (/.../node_modules/nats/lib/nats.js:405:16)
at emitOne (events.js:96:13)
Error
at Client.publish (/.../node_modules/nats/lib/nats.js:930:15)
at Stan.publishAsync (/.../node_modules/node-nats-streaming/lib/stan.js:410:11)
at Stan.<anonymous> (/.../a.js:6:10)
at emitOne (events.js:96:13)
at Stan.emit (events.js:188:7)
at /.../node_modules/node-nats-streaming/lib/stan.js:260:12
at Object.callback (/.../node_modules/nats/lib/nats.js:1121:9)
at Client.processMsg (/.../node_modules/nats/lib/nats.js:873:17)
at Client.processInbound (/.../node_modules/nats/lib/nats.js:805:24)
at Socket.<anonymous> (/.../node_modules/nats/lib/nats.js:405:16)
Error
at Client.publish (/.../node_modules/nats/lib/nats.js:930:15)
at Client.request (/.../node_modules/nats/lib/nats.js:1123:10)
at Stan.subscribe (/.../node_modules/node-nats-streaming/lib/stan.js:493:11)
at Stan.<anonymous> (/.../a.js:15:29)
at emitOne (events.js:96:13)
at Stan.emit (events.js:188:7)
at /.../node_modules/node-nats-streaming/lib/stan.js:260:12
at Object.callback (/.../node_modules/nats/lib/nats.js:1121:9)
at Client.processMsg (/.../node_modules/nats/lib/nats.js:873:17)
at Client.processInbound (/.../node_modules/nats/lib/nats.js:805:24)
Error
at Client.publish (/.../node_modules/nats/lib/nats.js:930:15)
at Client.request (/.../node_modules/nats/lib/nats.js:1123:10)
at Subscription.unsubscribe (/.../node_modules/node-nats-streaming/lib/stan.js:587:19)
at Stan.<anonymous> (/.../a.js:21:18)
at emitOne (events.js:96:13)
at Stan.emit (events.js:188:7)
at /.../node_modules/node-nats-streaming/lib/stan.js:260:12
at Object.callback (/.../node_modules/nats/lib/nats.js:1121:9)
at Client.processMsg (/.../node_modules/nats/lib/nats.js:873:17)
at Client.processInbound (/.../node_modules/nats/lib/nats.js:805:24)
Error
at Client.publish (/.../node_modules/nats/lib/nats.js:930:15)
at Client.request (/.../node_modules/nats/lib/nats.js:1123:10)
at Stan.close (/.../node_modules/node-nats-streaming/lib/stan.js:299:11)
at Stan.<anonymous> (/.../a.js:24:10)
at emitOne (events.js:96:13)
at Stan.emit (events.js:188:7)
at /.../node_modules/node-nats-streaming/lib/stan.js:260:12
at Object.callback (/.../node_modules/nats/lib/nats.js:1121:9)
at Client.processMsg (/.../node_modules/nats/lib/nats.js:873:17)
at Client.processInbound (/.../node_modules/nats/lib/nats.js:805:24)
events.js:160
throw er; // Unhandled 'error' event
^
Error: stan: invalid subscription
at /.../node_modules/node-nats-streaming/lib/stan.js:592:26
at Object.callback (/.../node_modules/nats/lib/nats.js:1121:9)
at Client.processMsg (/.../node_modules/nats/lib/nats.js:873:17)
at Client.processInbound (/.../node_modules/nats/lib/nats.js:805:24)
at Socket.<anonymous> (/.../node_modules/nats/lib/nats.js:405:16)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
at TCP.onread (net.js:543:20)
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
RichardLitt/standard-readme: A standard style for README files
A standard style for README files. Your README file is normally the first entry point to your code. It should tell people why...
Read more >README File – Everything you Need to Know - Great Learning
A README file is a text file that describes and launches a project. It comprises information that is frequently needed to grasp the...
Read more >Keys to a well written README - Medium
The first thing to be familiar with when writing your README is markdown. ... Demo of instructions on how to run the example...
Read more >Homework: Writing a README
A README isn't just something that we add to a project and forget about. Instead, it's a living document that often changes as...
Read more >README.md template | Documenting your project - Drupal
Start the README.md with the project name (required). ... This introduction may be the same as the first paragraph on the project page....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you, @aricart. I’ve put basic.js into a new catalog and installed node-nats-streaming as you’ve shown. It works.
Can you attach your node_modules/nats/lib/nats.js file. Your version is not matching mine.
Alternatively, you can delete nats and node-nats-streaming from node_modules, and do
npm install node-nats-streaming