Merge pull request #33415 from jacobgardner/feature/amqp-connection

amqplib: Add serverProperties to Connection object
This commit is contained in:
Nathan Shively-Sanders
2019-03-06 11:20:21 -08:00
committed by GitHub
4 changed files with 30 additions and 2 deletions
+16
View File
@@ -14,6 +14,14 @@ amqp.connect('amqp://localhost')
amqp.connect('amqp://localhost')
.then(connection => {
connection.serverProperties.copyright; // $ExpectType string | undefined
connection.serverProperties.platform; // $ExpectType string
connection.serverProperties.information; // $ExpectType string
connection.serverProperties.host; // $ExpectType string
connection.serverProperties.product; // $ExpectType string
connection.serverProperties.version; // $ExpectType string
connection.serverProperties.customField; // $ExpectType string | undefined
return connection.createChannel()
.tap(channel => channel.checkQueue('myQueue'))
.then(channel => {
@@ -37,6 +45,14 @@ import amqpcb = require('amqplib/callback_api');
amqpcb.connect('amqp://localhost', (err, connection) => {
if (!err) {
connection.serverProperties.copyright; // $ExpectType string | undefined
connection.serverProperties.platform; // $ExpectType string
connection.serverProperties.information; // $ExpectType string
connection.serverProperties.host; // $ExpectType string
connection.serverProperties.product; // $ExpectType string
connection.serverProperties.version; // $ExpectType string
connection.serverProperties.customField; // $ExpectType string | undefined
connection.createChannel((err, channel) => {
if (!err) {
channel.assertQueue('myQueue', {}, (err, ok) => {
+2 -1
View File
@@ -1,11 +1,12 @@
import events = require('events');
import { Replies, Options, Message } from './properties';
import { Replies, Options, Message, ServerProperties } from './properties';
export * from './properties';
export interface Connection extends events.EventEmitter {
close(callback?: (err: any) => void): void;
createChannel(callback: (err: any, channel: Channel) => void): void;
createConfirmChannel(callback: (err: any, confirmChannel: ConfirmChannel) => void): void;
serverProperties: ServerProperties;
}
export interface Channel extends events.EventEmitter {
+2 -1
View File
@@ -8,13 +8,14 @@
import * as Promise from 'bluebird';
import * as events from 'events';
import { Replies, Options, Message, GetMessage, ConsumeMessage } from './properties';
import { Replies, Options, Message, GetMessage, ConsumeMessage, ServerProperties } from './properties';
export * from './properties';
export interface Connection extends events.EventEmitter {
close(): Promise<void>;
createChannel(): Promise<Channel>;
createConfirmChannel(): Promise<ConfirmChannel>;
serverProperties: ServerProperties;
}
export interface Channel extends events.EventEmitter {
+10
View File
@@ -210,3 +210,13 @@ export interface XDeath {
"original-expiration"?: any;
"routing-keys": string[];
}
export interface ServerProperties {
host: string;
product: string;
version: string;
platform: string;
copyright?: string;
information: string;
[key: string]: string | undefined;
}