Fix publish and sendToQueue signatures. (#41217)

As per the
[documentation](https://github.com/benbria/node-amqp-connection-manager#amqpconnectionmanagercreatechanneloptions), the
`content` field in `publish` and `sendToQueue` can be a plain object, when `createChannel`s `json` option is set.

This commit extends the `content` parameter of those two functions. The change should be backwards compatible, as we're
loosening requirements.

Fixes #37295
This commit is contained in:
Timm Stelzer
2020-01-03 01:58:11 +01:00
committed by Ryan Cavanaugh
parent 533f14207e
commit 827e5dac59
2 changed files with 6 additions and 2 deletions

View File

@@ -24,6 +24,9 @@ channelWrapper.sendToQueue("foo", Buffer.from("bar"))
// nothing
});
// Test that plain objects are implicitly serialized.
channelWrapper.sendToQueue("foo", {a: 'bar'}).catch(_ => {});
// Checking connection options
amqpConMgr.connect(["foo", "bar"], {
findServers(callback) {

View File

@@ -1,6 +1,7 @@
// Type definitions for amqp-connection-manager 2.0
// Project: https://github.com/benbria/node-amqp-connection-manager
// Definitions by: rogierschouten <https://github.com/rogierschouten>
// tstelzer <https://github.com/tstelzer>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.2
@@ -158,7 +159,7 @@ export interface ChannelWrapper extends EventEmitter {
* @param options
* @param callback
*/
publish(exchange: string, routingKey: string, content: Buffer, options?: Options.Publish, callback?: (err: any, ok: Replies.Empty) => void): Promise<void>;
publish(exchange: string, routingKey: string, content: Buffer | object, options?: Options.Publish, callback?: (err: any, ok: Replies.Empty) => void): Promise<void>;
/**
* @see amqplib
@@ -167,7 +168,7 @@ export interface ChannelWrapper extends EventEmitter {
* @param options
* @param callback
*/
sendToQueue(queue: string, content: Buffer, options?: Options.Publish, callback?: (err: any, ok: Replies.Empty) => void): Promise<void>;
sendToQueue(queue: string, content: Buffer | object, options?: Options.Publish, callback?: (err: any, ok: Replies.Empty) => void): Promise<void>;
/**
* @see amqplib