@toa.io/bindings.amqp 0.4.0 → 0.6.0-dev.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/LICENSE +22 -0
- package/package.json +8 -8
- 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/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2020-present Artem Gurtovoi
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toa.io/bindings.amqp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0-dev.3",
|
|
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.
|
|
22
|
+
"@toa.io/mock": "0.6.0-dev.3"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@toa.io/console": "0.
|
|
26
|
-
"@toa.io/core": "0.
|
|
27
|
-
"@toa.io/generic": "0.
|
|
28
|
-
"@toa.io/generics.amqp": "0.
|
|
29
|
-
"@toa.io/pointer": "0.
|
|
25
|
+
"@toa.io/console": "0.6.0-dev.1",
|
|
26
|
+
"@toa.io/core": "0.6.0-dev.3",
|
|
27
|
+
"@toa.io/generic": "0.6.0-dev.1",
|
|
28
|
+
"@toa.io/generics.amqp": "0.6.0-dev.2",
|
|
29
|
+
"@toa.io/pointer": "0.6.0-dev.1"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "08ffb832d6593ec1b42bff71cfbfd8fcd871c501"
|
|
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
|
+
})
|