mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-15 01:32:56 +08:00
Add definitions for amqp-rpc
This commit is contained in:
42
amqp-rpc/amqp-rpc-tests.ts
Normal file
42
amqp-rpc/amqp-rpc-tests.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
/// <reference path="./amqp-rpc.d.ts" />
|
||||
import amqp_rpc = require('amqp-rpc');
|
||||
var rpc = amqp_rpc.factory();
|
||||
|
||||
interface Name {
|
||||
name?: string;
|
||||
}
|
||||
|
||||
rpc.on<number>('inc', function (param, cb) {
|
||||
var prevVal = param;
|
||||
var nextVal = param + 2;
|
||||
cb(++param, prevVal, nextVal);
|
||||
});
|
||||
|
||||
rpc.on<Name>('say.*', function (param, cb, inf) {
|
||||
var arr = inf.cmd.split('.');
|
||||
var name = (param && param.name) ? param.name : 'world';
|
||||
cb(arr[1] + ' ' + name + '!');
|
||||
});
|
||||
|
||||
rpc.on('withoutCB', function (param, cb, inf) {
|
||||
if (cb) {
|
||||
cb('please run function without cb parameter')
|
||||
}
|
||||
else {
|
||||
console.log('this is function withoutCB');
|
||||
}
|
||||
});
|
||||
|
||||
rpc.call<number>('inc', 5, function (param1, param2, param3) {
|
||||
console.log(param1, param2, param3);
|
||||
});
|
||||
|
||||
rpc.call<Name>('say.Hello', { name: 'John' }, function (msg) {
|
||||
console.log('results of say.Hello:', msg); //output: Hello John!
|
||||
});
|
||||
|
||||
rpc.call<any>('withoutCB', {}, function (msg) {
|
||||
console.log('withoutCB results:', msg); //output: please run function without cb parameter
|
||||
});
|
||||
|
||||
rpc.call<any>('withoutCB', {}); //output message on server side console
|
||||
68
amqp-rpc/amqp-rpc.d.ts
vendored
Normal file
68
amqp-rpc/amqp-rpc.d.ts
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
// Type definitions for amqp-rpc v0.0.8
|
||||
// Project: https://github.com/demchenkoe/node-amqp-rpc/
|
||||
// Definitions by: Wonshik Kim <https://github.com/wokim/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../node/node.d.ts" />
|
||||
|
||||
declare module "amqp-rpc" {
|
||||
|
||||
export interface Options {
|
||||
connection?: any;
|
||||
url?: string;
|
||||
exchangeInstance?: any;
|
||||
exchange?: string;
|
||||
exchange_options?: {
|
||||
exclusive?: boolean;
|
||||
autoDelete?: boolean;
|
||||
};
|
||||
ipml_options?: {
|
||||
defaultExchangeName?: string;
|
||||
}
|
||||
conn_options?: any;
|
||||
}
|
||||
|
||||
export interface CallOptions {
|
||||
correlationId?: string;
|
||||
autoDeleteCallback?: any;
|
||||
}
|
||||
|
||||
export interface HandlerOptions {
|
||||
queueName?: string;
|
||||
durable?: boolean;
|
||||
exclusive?: boolean;
|
||||
autoDelete?: boolean;
|
||||
}
|
||||
|
||||
export interface BroadcastOptions {
|
||||
ttl?: boolean;
|
||||
onResponse?: any;
|
||||
context?: any;
|
||||
onComplete?: any;
|
||||
}
|
||||
|
||||
export interface CommandInfo {
|
||||
cmd?: string;
|
||||
exchange?: string;
|
||||
contentType?: string;
|
||||
size?: number;
|
||||
}
|
||||
|
||||
export interface Callback {
|
||||
(...args: any[]): void;
|
||||
}
|
||||
|
||||
export function factory(opt?: Options): amqpRPC;
|
||||
|
||||
export class amqpRPC {
|
||||
constructor(opt?: Options);
|
||||
generateQueueName(type: string): string;
|
||||
disconnect(): void;
|
||||
call<T>(cmd: string, params: T, cb?: Callback, context?: any, options?: CallOptions): string;
|
||||
on<T>(cmd: string, cb: (param?: T, cb?: Callback, info?: CommandInfo) => void, context?: any, options?: HandlerOptions): boolean;
|
||||
off(cmd: string): boolean;
|
||||
callBroadcast(cmd: string, params: any, options: BroadcastOptions): void;
|
||||
onBroadcast(cmd: string, cb: (err: any) => void, context: any, options?: any): boolean;
|
||||
offBroadcast(cmd: string): boolean;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user