comq 0.11.1 → 0.11.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lerna.json +1 -1
- package/package.json +1 -1
- package/readme.md +4 -4
- package/source/channel.js +2 -0
- package/source/encoders/json.js +4 -0
- package/source/io.js +1 -1
- package/test/channel.test.js +7 -0
- package/test/io.emit.test.js +2 -2
- package/test/io.request.test.js +2 -2
- package/types/io.d.ts +1 -1
package/lerna.json
CHANGED
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -283,9 +283,9 @@ At the same time, there is no guarantee that the stream will be transmitted to t
|
|
|
283
283
|
|
|
284
284
|
## Encoding
|
|
285
285
|
|
|
286
|
-
By default, outgoing message contents are encoded with
|
|
287
|
-
the `contentType` property is set to `application/
|
|
288
|
-
specified ([request](#request), [emit](#emission)), contents are encoded accordingly.
|
|
286
|
+
By default, outgoing message contents are encoded with JSON and
|
|
287
|
+
the `contentType` property is set to `application/json`.
|
|
288
|
+
If the encoding format is specified ([request](#request), [emit](#emission)), contents are encoded accordingly.
|
|
289
289
|
|
|
290
290
|
Exceptions are Buffers, which are sent without encoding and the `contentType` property set
|
|
291
291
|
to specified encoding format or `application/octet-stream` by default.
|
|
@@ -298,8 +298,8 @@ If the specified encoding format is not supported, an exception will be thrown.
|
|
|
298
298
|
|
|
299
299
|
The following encoding formats are supported:
|
|
300
300
|
|
|
301
|
-
- `application/msgpack`
|
|
302
301
|
- `application/json`
|
|
302
|
+
- `application/msgpack`
|
|
303
303
|
- `application/octet-stream`
|
|
304
304
|
- `text/plain`
|
|
305
305
|
|
package/source/channel.js
CHANGED
|
@@ -58,6 +58,8 @@ class Channel {
|
|
|
58
58
|
if (this.#topology.confirms) this.#channel = await this.#connection.createConfirmChannel()
|
|
59
59
|
else this.#channel = await this.#connection.createChannel()
|
|
60
60
|
|
|
61
|
+
await this.#channel.prefetch(this.#topology.prefetch)
|
|
62
|
+
|
|
61
63
|
this.#channel.on('drain', this.#unpause)
|
|
62
64
|
this.#channel.on('return', (message) => this.#diagnostics.emit('return', message))
|
|
63
65
|
}
|
package/source/encoders/json.js
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
* @returns {Buffer}
|
|
6
6
|
*/
|
|
7
7
|
const encode = (value) => {
|
|
8
|
+
if (value === undefined) { return Buffer.alloc(0) }
|
|
9
|
+
|
|
8
10
|
const json = JSON.stringify(value)
|
|
9
11
|
|
|
10
12
|
return Buffer.from(json)
|
|
@@ -14,6 +16,8 @@ const encode = (value) => {
|
|
|
14
16
|
* @param {Buffer} buffer
|
|
15
17
|
*/
|
|
16
18
|
const decode = (buffer) => {
|
|
19
|
+
if (buffer.length === 0) { return undefined }
|
|
20
|
+
|
|
17
21
|
const json = buffer.toString()
|
|
18
22
|
|
|
19
23
|
return JSON.parse(json)
|
package/source/io.js
CHANGED
|
@@ -452,7 +452,7 @@ class IO {
|
|
|
452
452
|
const OCTETS = 'application/octet-stream'
|
|
453
453
|
|
|
454
454
|
/** @type {comq.Encoding} */
|
|
455
|
-
const DEFAULT = 'application/
|
|
455
|
+
const DEFAULT = 'application/json'
|
|
456
456
|
|
|
457
457
|
const RETRANSMISSION = /** @type {Error} */ Symbol('retransmission')
|
|
458
458
|
|
package/test/channel.test.js
CHANGED
|
@@ -42,6 +42,13 @@ it('should return Channel', async () => {
|
|
|
42
42
|
expect(channel).toBeDefined()
|
|
43
43
|
})
|
|
44
44
|
|
|
45
|
+
it('should set prefetch limit', async () => {
|
|
46
|
+
channel = await create(connection, topology)
|
|
47
|
+
chan = await getCreatedChannel()
|
|
48
|
+
|
|
49
|
+
expect(chan.prefetch).toHaveBeenCalledWith(topology.prefetch)
|
|
50
|
+
})
|
|
51
|
+
|
|
45
52
|
it.each([true, false])('should create channel (confirms: %s)', async (confirms) => {
|
|
46
53
|
const method = `create${confirms ? 'Confirm' : ''}Channel`
|
|
47
54
|
|
package/test/io.emit.test.js
CHANGED
|
@@ -64,8 +64,8 @@ it('should publish stream of events', async () => {
|
|
|
64
64
|
expect(events.publish).toHaveBeenCalledTimes(10)
|
|
65
65
|
})
|
|
66
66
|
|
|
67
|
-
it('should encode message as
|
|
68
|
-
const encoding = 'application/
|
|
67
|
+
it('should encode message as json by default', async () => {
|
|
68
|
+
const encoding = 'application/json'
|
|
69
69
|
const buf = encode(payload, encoding)
|
|
70
70
|
const [, buffer, properties] = events.publish.mock.calls[0]
|
|
71
71
|
|
package/test/io.request.test.js
CHANGED
|
@@ -96,9 +96,9 @@ describe('send', () => {
|
|
|
96
96
|
expect(properties.replyTo).toStrictEqual(queue)
|
|
97
97
|
})
|
|
98
98
|
|
|
99
|
-
it('should encode message with
|
|
99
|
+
it('should encode message with json by default', async () => {
|
|
100
100
|
/** @type {comq.Encoding} */
|
|
101
|
-
const contentType = 'application/
|
|
101
|
+
const contentType = 'application/json'
|
|
102
102
|
const buffer = encode(payload, contentType)
|
|
103
103
|
|
|
104
104
|
expect(call[1]).toStrictEqual(buffer)
|
package/types/io.d.ts
CHANGED
|
@@ -51,7 +51,7 @@ declare namespace comq {
|
|
|
51
51
|
|
|
52
52
|
enqueue (exchange: string, stream: Readable, properties?: _amqp.Properties): Promise<void>
|
|
53
53
|
|
|
54
|
-
process<T = any> (queue: string,
|
|
54
|
+
process<T = any> (queue: string, processor: Consumer<T>): Promise<void>
|
|
55
55
|
|
|
56
56
|
seal (): Promise<void>
|
|
57
57
|
|