@toa.io/bindings.amqp 0.6.0-dev.1 → 0.6.0-dev.4
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/package.json +6 -6
- package/source/emitter.js +3 -1
- package/source/receiver.js +11 -1
- package/test/emitter.test.js +11 -1
- package/test/receiver.test.js +18 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toa.io/bindings.amqp",
|
|
3
|
-
"version": "0.6.0-dev.
|
|
3
|
+
"version": "0.6.0-dev.4",
|
|
4
4
|
"description": "Toa AMQP Binding",
|
|
5
5
|
"author": "temich <tema.gurtovoy@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/toa-io/toa#readme",
|
|
@@ -19,14 +19,14 @@
|
|
|
19
19
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@toa.io/mock": "0.6.0-dev.
|
|
22
|
+
"@toa.io/mock": "0.6.0-dev.4"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@toa.io/console": "0.6.0-dev.1",
|
|
26
|
-
"@toa.io/core": "0.6.0-dev.
|
|
26
|
+
"@toa.io/core": "0.6.0-dev.4",
|
|
27
27
|
"@toa.io/generic": "0.6.0-dev.1",
|
|
28
|
-
"@toa.io/generics.amqp": "0.6.0-dev.
|
|
29
|
-
"@toa.io/pointer": "0.6.0-dev.
|
|
28
|
+
"@toa.io/generics.amqp": "0.6.0-dev.3",
|
|
29
|
+
"@toa.io/pointer": "0.6.0-dev.2"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "64ed74a84a57955b905fdd331b655bf4bd9bf3b2"
|
|
32
32
|
}
|
package/source/emitter.js
CHANGED
|
@@ -29,8 +29,10 @@ class Emitter extends Connector {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
async emit (message) {
|
|
32
|
-
await this.#comm.emit(this.#exchange, message)
|
|
32
|
+
await this.#comm.emit(this.#exchange, message, PROPERTIES)
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
const PROPERTIES = { headers: { 'toa.io/amqp': '0' } }
|
|
37
|
+
|
|
36
38
|
exports.Emitter = Emitter
|
package/source/receiver.js
CHANGED
|
@@ -33,7 +33,17 @@ class Receiver extends Connector {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
async open () {
|
|
36
|
-
await this.#comm.consume(this.#exchange, this.#group,
|
|
36
|
+
await this.#comm.consume(this.#exchange, this.#group, this.#receive)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @param {any} message
|
|
41
|
+
* @param {object} properties
|
|
42
|
+
*/
|
|
43
|
+
#receive = async (message, properties) => {
|
|
44
|
+
if (!('toa.io/amqp' in properties.headers)) message = { payload: message }
|
|
45
|
+
|
|
46
|
+
await this.#receiver.receive(message)
|
|
37
47
|
}
|
|
38
48
|
}
|
|
39
49
|
|
package/test/emitter.test.js
CHANGED
|
@@ -49,6 +49,16 @@ it('should emit', async () => {
|
|
|
49
49
|
expect(mock.queues.name).toHaveBeenCalledWith(locator, label)
|
|
50
50
|
|
|
51
51
|
const exchange = mock.queues.name.mock.results[0].value
|
|
52
|
+
const args = comm.emit.mock.calls[0]
|
|
52
53
|
|
|
53
|
-
expect(
|
|
54
|
+
expect(args[0]).toStrictEqual(exchange)
|
|
55
|
+
expect(args[1]).toStrictEqual(message)
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('should set authored header', async () => {
|
|
59
|
+
const message = generate()
|
|
60
|
+
|
|
61
|
+
await emitter.emit(message)
|
|
62
|
+
|
|
63
|
+
expect(comm.emit.mock.calls[0][2]).toMatchObject({ headers: { 'toa.io/amqp': '0' } })
|
|
54
64
|
})
|
package/test/receiver.test.js
CHANGED
|
@@ -51,9 +51,25 @@ it('should consume events', async () => {
|
|
|
51
51
|
expect(comm.consume).toHaveBeenCalledWith(exchange, group, expect.any(Function))
|
|
52
52
|
|
|
53
53
|
const callback = comm.consume.mock.calls[0][2]
|
|
54
|
-
const
|
|
54
|
+
const payload = generate()
|
|
55
|
+
const message = { payload }
|
|
56
|
+
const properties = { headers: { 'toa.io/amqp': '0' } }
|
|
55
57
|
|
|
56
|
-
await callback(message)
|
|
58
|
+
await callback(message, properties)
|
|
57
59
|
|
|
58
60
|
expect(processor.receive).toHaveBeenCalledWith(message)
|
|
59
61
|
})
|
|
62
|
+
|
|
63
|
+
it('should consume foreign events', async () => {
|
|
64
|
+
await receiver.open()
|
|
65
|
+
|
|
66
|
+
expect(comm.consume).toHaveBeenCalledWith(exchange, group, expect.any(Function))
|
|
67
|
+
|
|
68
|
+
const callback = comm.consume.mock.calls[0][2]
|
|
69
|
+
const message = generate()
|
|
70
|
+
const properties = { headers: {} }
|
|
71
|
+
|
|
72
|
+
await callback(message, properties)
|
|
73
|
+
|
|
74
|
+
expect(processor.receive).toHaveBeenCalledWith({ payload: message })
|
|
75
|
+
})
|