Skip to content

Commit

Permalink
Merge 9b86f5a into 85d5302
Browse files Browse the repository at this point in the history
  • Loading branch information
aricart committed Apr 10, 2019
2 parents 85d5302 + 9b86f5a commit 5c85688
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 47 deletions.
6 changes: 3 additions & 3 deletions index.d.ts
Expand Up @@ -153,9 +153,9 @@ declare class Client extends events.EventEmitter {
* a timeout has been reached.
* The Subscriber Id is returned.
*/
requestOne(subject: string, timeout: number, callback: Function);
requestOne(subject: string, msg: any, timeout: number, callback: Function);
requestOne(subject: string, msg: any, options: SubscribeOptions, timeout: number, callback: Function);
requestOne(subject: string, timeout: number, callback: Function): number;
requestOne(subject: string, msg: any, timeout: number, callback: Function): number;
requestOne(subject: string, msg: any, options: SubscribeOptions, timeout: number, callback: Function): number;

/**
* Report number of outstanding subscriptions on this connection.
Expand Down
2 changes: 1 addition & 1 deletion lib/nats.js
Expand Up @@ -32,7 +32,7 @@ const net = require('net'),
/**
* Constants
*/
const VERSION = '1.2.8',
const VERSION = '1.2.10',

DEFAULT_PORT = 4222,
DEFAULT_PRE = 'nats://localhost:',
Expand Down
45 changes: 7 additions & 38 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "nats",
"version": "1.2.8",
"version": "1.2.10",
"description": "Node.js client for NATS, a lightweight, high-performance cloud native messaging system",
"keywords": [
"nats",
Expand Down Expand Up @@ -31,7 +31,8 @@
"depcheck": "dependency-check . lib/*",
"depcheck:unused": "dependency-check ./package.json --unused --no-dev lib/*",
"test:unit": "mkdir -p reports/ && NODE_ENV=test multi='spec=- xunit=reports/mocha-xunit.xml' nyc mocha --timeout 10000 --slow 750",
"test": "npm run depcheck && npm run depcheck:unused && npm run lint && npm run test:unit",
"test": "npm run depcheck && npm run depcheck:unused && npm run lint && npm run test:typescript && npm run test:unit",
"test:typescript": "./node_modules/typescript/bin/tsc --strict --noEmit tstest/main.ts",
"coveralls": "npm run test && nyc report --reporter=text-lcov | coveralls",
"cover": "nyc report --reporter=html && open coverage/index.html",
"lint": "eslint ./lib ./examples ./benchmark ./test",
Expand All @@ -46,18 +47,19 @@
},
"devDependencies": {
"@types/node": "^11.11.6",
"minimist": "^1.2.0",
"coveralls": "^3.0.2",
"dependency-check": "^3.2.1",
"eslint": "^5.10.0",
"nyc": "^13.3.0",
"js-beautify": "^1.6.12",
"jshint": "^2.9.6",
"jshint-stylish": "2.2.x",
"minimist": "^1.2.0",
"mocha": "^5.2.0",
"mocha-lcov-reporter": "1.2.x",
"mocha-multi": "^1.0.1",
"should": ">= 9.0.0"
"nyc": "^13.3.0",
"should": ">= 9.0.0",
"typescript": "^3.4.3"
},
"typings": "./index.d.ts",
"nyc": {
Expand Down
96 changes: 96 additions & 0 deletions tstest/main.ts
@@ -0,0 +1,96 @@
/*
* Copyright 2013-2019 The NATS Authors
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {connect} from '..'

const nc = connect("localhost:4222");


// sub min
let sid = nc.subscribe('foo', (payload: string, replyTo: string, subject: string) => {
console.log(`sub1 handler: payload: ${payload} replyTo: ${replyTo} subject: ${subject}`);
});
console.log(sid);

nc.subscribe('foo', {queue: 'one'}, (payload: string, replyTo: string, subject: string) => {
console.log(`sub2 handler: payload: ${payload} replyTo: ${replyTo} subject: ${subject}`);
});

nc.subscribe('bar', (payload: string, replyTo: string, subject: string) => {
console.log(`bar request handler: payload: ${payload} replyTo: ${replyTo} subject: ${subject}`);
if(replyTo) {
nc.publish(replyTo, payload);
}
});

// sub all
sid = nc.subscribe('foo', {max: 1}, () => {
});
console.log(sid);



nc.publish('foo');
nc.publish('foo', () => {
console.log('published');
});

nc.publish('foo', 'payload');
nc.publish('foo', 'payload', () => {
console.log('published with payload');
});

nc.publish('foo', 'payload', 'here');
nc.publish('foo', 'payload', 'here', () => {
console.log('published with payload and reply');
});


// request min
let rid = nc.request('bar', (payload:string) => {
console.log(`request not expecting payload: ${payload}` );
});
console.log(rid);

// request payload
rid = nc.request('bar', 'payload', (payload:string) => {
console.log(`request expecting payload: ${payload}`, );
});
console.log(rid);

// request all
rid = nc.request('bar', 'payload', {max: 5}, (payload:string) => {
console.log(`request expecting payload: ${payload}`, );
});
console.log(rid);


// requestOne min
let roid = nc.requestOne('bar', 100, (payload:string) => {
console.log(`requestOne not expecting payload: ${payload}`);
});
console.log(roid);

// requestOne payload
roid = nc.requestOne('bar', 'payload', 100, (payload:string) => {
console.log(`requestOne expecting payload: ${payload}`);
});
console.log(roid);

// requestOne all
roid = nc.requestOne('bar', 'payload', {max: 10}, 100, (payload:string) => {
console.log(`requestOne expecting payload: ${payload}`);
});
console.log(roid);

0 comments on commit 5c85688

Please sign in to comment.