comq 0.4.0-dev.0 → 0.4.0-dev.5
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/.github/workflows/release.yaml +53 -0
- package/.husky/pre-commit +4 -0
- package/LICENSE +21 -0
- package/docs/notes.md +1 -1
- package/features/steps/.test/backpressure.test.js +5 -5
- package/features/steps/.test/broker.test.js +4 -4
- package/features/steps/.test/comq.mock.js +0 -2
- package/features/steps/.test/connection.test.js +10 -10
- package/features/steps/.test/events.test.js +7 -7
- package/features/steps/.test/poison.test.js +4 -4
- package/features/steps/.test/rpc.test.js +9 -9
- package/features/steps/broker.js +1 -1
- package/features/steps/context.js +1 -1
- package/lerna.json +5 -0
- package/package.json +31 -9
- package/readme.md +3 -2
- package/source/io.js +5 -2
- package/test/io.close.test.js +1 -1
- package/test/io.reply.test.js +1 -1
- package/test/io.request.test.js +30 -3
- package/types/io.d.ts +1 -1
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
types: [closed]
|
|
6
|
+
branches:
|
|
7
|
+
- main
|
|
8
|
+
- dev
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
publish:
|
|
12
|
+
if: github.event.pull_request.merged == true
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
|
|
15
|
+
steps:
|
|
16
|
+
- name: Setup Node
|
|
17
|
+
uses: actions/setup-node@v3
|
|
18
|
+
with:
|
|
19
|
+
node-version: 16
|
|
20
|
+
registry-url: 'https://registry.npmjs.org'
|
|
21
|
+
|
|
22
|
+
- name: Checkout
|
|
23
|
+
uses: actions/checkout@v3
|
|
24
|
+
with:
|
|
25
|
+
fetch-depth: 0
|
|
26
|
+
|
|
27
|
+
- name: Run tests
|
|
28
|
+
run: npm i && npm test
|
|
29
|
+
|
|
30
|
+
- name: Bump version
|
|
31
|
+
run: |
|
|
32
|
+
git config user.name "toabot"
|
|
33
|
+
git config user.email "127577558+toabot@users.noreply.github.com"
|
|
34
|
+
|
|
35
|
+
if [ ${{ github.base_ref }} = main ]; then
|
|
36
|
+
npx lerna@6.5.1 version --conventional-graduate --no-commit-hooks --no-changelog --yes --message "chore(release): %s"
|
|
37
|
+
git fetch
|
|
38
|
+
git checkout dev
|
|
39
|
+
git merge main
|
|
40
|
+
git push --all origin --no-verify
|
|
41
|
+
else
|
|
42
|
+
npx lerna@6.5.1 version --conventional-prerelease --preid dev --no-commit-hooks --no-changelog --yes --message "chore(prerelease): %s"
|
|
43
|
+
fi
|
|
44
|
+
|
|
45
|
+
- name: Publish packages
|
|
46
|
+
env:
|
|
47
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
48
|
+
run: |
|
|
49
|
+
if [ ${{ github.base_ref }} = main ]; then
|
|
50
|
+
npm publish
|
|
51
|
+
else
|
|
52
|
+
npm publish --tag dev
|
|
53
|
+
fi
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Toa
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/docs/notes.md
CHANGED
|
@@ -21,7 +21,7 @@ The current message is acknowledged once the Producer function is completed, whi
|
|
|
21
21
|
considered to be published when a confirmation is received from the broker.
|
|
22
22
|
|
|
23
23
|
In summary, the next "cause" message will be consumed from the queue only after the "effect" message
|
|
24
|
-
publication has been confirmed. Due to the
|
|
24
|
+
publication has been confirmed. Due to the "at least once" effect, *there is a
|
|
25
25
|
delay between the moment when a Reply **is delivered** to the Consumer and the moment when the
|
|
26
26
|
next Request is consumed from the Request queue*.
|
|
27
27
|
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
const { AssertionError } = require('node:assert')
|
|
4
4
|
const { generate } = require('randomstring')
|
|
5
5
|
const { random, quantity } = require('@toa.io/generic')
|
|
6
|
-
const
|
|
6
|
+
const tomato = require('@toa.io/tomato')
|
|
7
7
|
const { io } = require('./io.mock')
|
|
8
|
-
const mock = {
|
|
8
|
+
const mock = { tomato }
|
|
9
9
|
|
|
10
|
-
jest.mock('@cucumber/cucumber', () => mock.
|
|
10
|
+
jest.mock('@cucumber/cucumber', () => mock.tomato)
|
|
11
11
|
|
|
12
12
|
require('../backpressure')
|
|
13
13
|
|
|
@@ -15,7 +15,7 @@ require('../backpressure')
|
|
|
15
15
|
let context
|
|
16
16
|
|
|
17
17
|
describe('When I\'m sending {quantity}B requests to the {token} queue at {quantity}Hz for {number} second(s)', () => {
|
|
18
|
-
const step =
|
|
18
|
+
const step = tomato.steps.Wh('I\'m sending {quantity}B requests to the {token} queue at {quantity}Hz for {number} second(s)')
|
|
19
19
|
|
|
20
20
|
it('should be', async () => undefined)
|
|
21
21
|
|
|
@@ -59,7 +59,7 @@ describe('When I\'m sending {quantity}B requests to the {token} queue at {quanti
|
|
|
59
59
|
})
|
|
60
60
|
|
|
61
61
|
describe('Then back pressure was applied', () => {
|
|
62
|
-
const step =
|
|
62
|
+
const step = tomato.steps.Th('back pressure was applied')
|
|
63
63
|
|
|
64
64
|
beforeEach(() => {
|
|
65
65
|
context = /** @type {comq.features.Context} */ { io }
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const { generate } = require('randomstring')
|
|
4
|
-
const
|
|
4
|
+
const tomato = require('@toa.io/tomato')
|
|
5
5
|
const { command } = require('./command.mock')
|
|
6
|
-
const mock = {
|
|
6
|
+
const mock = { tomato, command }
|
|
7
7
|
|
|
8
|
-
jest.mock('@cucumber/cucumber', () => mock.
|
|
8
|
+
jest.mock('@cucumber/cucumber', () => mock.tomato)
|
|
9
9
|
jest.mock('@toa.io/command', () => mock.command)
|
|
10
10
|
|
|
11
11
|
jest.setTimeout(10000)
|
|
@@ -19,7 +19,7 @@ beforeEach(() => {
|
|
|
19
19
|
})
|
|
20
20
|
|
|
21
21
|
describe('the broker is/has {status}', () => {
|
|
22
|
-
const step =
|
|
22
|
+
const step = tomato.steps.Gi('the broker is/has {status}')
|
|
23
23
|
|
|
24
24
|
it('should be', async () => undefined)
|
|
25
25
|
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
const { AssertionError } = require('node:assert')
|
|
4
4
|
const { generate } = require('randomstring')
|
|
5
5
|
const { random, promex } = require('@toa.io/generic')
|
|
6
|
-
const
|
|
6
|
+
const tomato = require('@toa.io/tomato')
|
|
7
7
|
const { comq } = require('./comq.mock')
|
|
8
8
|
const world = require('./context.mock')
|
|
9
|
-
const mock = {
|
|
9
|
+
const mock = { tomato, comq }
|
|
10
10
|
|
|
11
|
-
jest.mock('@cucumber/cucumber', () => mock.
|
|
11
|
+
jest.mock('@cucumber/cucumber', () => mock.tomato)
|
|
12
12
|
jest.mock('comq', () => mock.comq)
|
|
13
13
|
|
|
14
14
|
require('../connection')
|
|
@@ -23,7 +23,7 @@ beforeEach(() => {
|
|
|
23
23
|
})
|
|
24
24
|
|
|
25
25
|
describe('Given an active connection to the broker', () => {
|
|
26
|
-
const step =
|
|
26
|
+
const step = tomato.steps.Gi('an active connection to the broker')
|
|
27
27
|
|
|
28
28
|
it('should be', async () => undefined)
|
|
29
29
|
|
|
@@ -37,7 +37,7 @@ describe('Given an active connection to the broker', () => {
|
|
|
37
37
|
})
|
|
38
38
|
|
|
39
39
|
describe('When I attempt to connect to the broker for {number} second(s)', () => {
|
|
40
|
-
const step =
|
|
40
|
+
const step = tomato.steps.Wh('I attempt to connect to the broker for {number} second(s)')
|
|
41
41
|
|
|
42
42
|
it('should be', async () => undefined)
|
|
43
43
|
|
|
@@ -89,7 +89,7 @@ describe('When I attempt to connect to the broker for {number} second(s)', () =>
|
|
|
89
89
|
})
|
|
90
90
|
|
|
91
91
|
describe('When I attempt to connect to the broker', () => {
|
|
92
|
-
const step =
|
|
92
|
+
const step = tomato.steps.Wh('I attempt to connect to the broker')
|
|
93
93
|
|
|
94
94
|
it('should be', async () => undefined)
|
|
95
95
|
|
|
@@ -111,7 +111,7 @@ describe('When I attempt to connect to the broker', () => {
|
|
|
111
111
|
})
|
|
112
112
|
|
|
113
113
|
describe('When I attempt to connect to the broker as {string} with password {string}', () => {
|
|
114
|
-
const step =
|
|
114
|
+
const step = tomato.steps.Wh('I attempt to connect to the broker as {string} with password {string}')
|
|
115
115
|
|
|
116
116
|
it('should be', async () => undefined)
|
|
117
117
|
|
|
@@ -126,7 +126,7 @@ describe('When I attempt to connect to the broker as {string} with password {str
|
|
|
126
126
|
})
|
|
127
127
|
|
|
128
128
|
describe.each([['', true], [' not', false]])('Then the connection is%s established', (not, defined) => {
|
|
129
|
-
const step =
|
|
129
|
+
const step = tomato.steps.Th(`the connection is${not} established`)
|
|
130
130
|
|
|
131
131
|
it('should be', async () => undefined)
|
|
132
132
|
|
|
@@ -144,7 +144,7 @@ describe.each([['', true], [' not', false]])('Then the connection is%s establish
|
|
|
144
144
|
})
|
|
145
145
|
|
|
146
146
|
describe('Then no exceptions are thrown', () => {
|
|
147
|
-
const step =
|
|
147
|
+
const step = tomato.steps.Th('no exceptions are thrown')
|
|
148
148
|
|
|
149
149
|
it('should be', async () => undefined)
|
|
150
150
|
|
|
@@ -160,7 +160,7 @@ describe('Then no exceptions are thrown', () => {
|
|
|
160
160
|
})
|
|
161
161
|
|
|
162
162
|
describe('Then an exception is thrown: {string}', () => {
|
|
163
|
-
const step =
|
|
163
|
+
const step = tomato.steps.Th('an exception is thrown: {string}')
|
|
164
164
|
|
|
165
165
|
const message = generate()
|
|
166
166
|
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
const { AssertionError } = require('node:assert')
|
|
4
4
|
const { generate } = require('randomstring')
|
|
5
5
|
const { promex } = require('@toa.io/generic')
|
|
6
|
-
const
|
|
6
|
+
const tomato = require('@toa.io/tomato')
|
|
7
7
|
const { io } = require('./io.mock')
|
|
8
|
-
const mock = {
|
|
8
|
+
const mock = { tomato }
|
|
9
9
|
|
|
10
|
-
jest.mock('@cucumber/cucumber', () => mock.
|
|
10
|
+
jest.mock('@cucumber/cucumber', () => mock.tomato)
|
|
11
11
|
|
|
12
12
|
require('../events')
|
|
13
13
|
|
|
@@ -21,7 +21,7 @@ beforeEach(() => {
|
|
|
21
21
|
})
|
|
22
22
|
|
|
23
23
|
describe('Given (that ){token} is consuming events from the {token} exchange', () => {
|
|
24
|
-
const step =
|
|
24
|
+
const step = tomato.steps.Gi('(that ){token} is consuming events from the {token} exchange')
|
|
25
25
|
|
|
26
26
|
it('should be', async () => undefined)
|
|
27
27
|
|
|
@@ -52,13 +52,13 @@ describe('Given (that ){token} is consuming events from the {token} exchange', (
|
|
|
52
52
|
})
|
|
53
53
|
|
|
54
54
|
describe('Given {token} consuming events from the {token} exchange is expected', () => {
|
|
55
|
-
|
|
55
|
+
tomato.steps.Gi('{token} consuming events from the {token} exchange is expected')
|
|
56
56
|
|
|
57
57
|
it('should be', async () => undefined)
|
|
58
58
|
})
|
|
59
59
|
|
|
60
60
|
describe('When I emit an event to the {token} exchange', () => {
|
|
61
|
-
const step =
|
|
61
|
+
const step = tomato.steps.Wh('I emit an event to the {token} exchange')
|
|
62
62
|
|
|
63
63
|
it('should be', async () => undefined)
|
|
64
64
|
|
|
@@ -98,7 +98,7 @@ describe('When I emit an event to the {token} exchange', () => {
|
|
|
98
98
|
})
|
|
99
99
|
|
|
100
100
|
describe('Then {token} receives the event', () => {
|
|
101
|
-
const step =
|
|
101
|
+
const step = tomato.steps.Th('{token} receives the event')
|
|
102
102
|
|
|
103
103
|
const payload = generate()
|
|
104
104
|
const group = generate()
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const { AssertionError } = require('node:assert')
|
|
4
|
-
const
|
|
5
|
-
const mock = {
|
|
4
|
+
const tomato = require('@toa.io/tomato')
|
|
5
|
+
const mock = { tomato }
|
|
6
6
|
|
|
7
|
-
jest.mock('@cucumber/cucumber', () => mock.
|
|
7
|
+
jest.mock('@cucumber/cucumber', () => mock.tomato)
|
|
8
8
|
|
|
9
9
|
require('../poison')
|
|
10
10
|
|
|
@@ -16,7 +16,7 @@ beforeEach(() => {
|
|
|
16
16
|
})
|
|
17
17
|
|
|
18
18
|
describe('Then the message is discarded', () => {
|
|
19
|
-
const step =
|
|
19
|
+
const step = tomato.steps.Th('the message is discarded')
|
|
20
20
|
|
|
21
21
|
it('should be', async () => undefined)
|
|
22
22
|
|
|
@@ -4,11 +4,11 @@ const { AssertionError } = require('node:assert')
|
|
|
4
4
|
const { generate } = require('randomstring')
|
|
5
5
|
const { promex } = require('@toa.io/generic')
|
|
6
6
|
const { dump } = require('@toa.io/yaml')
|
|
7
|
-
const
|
|
7
|
+
const tomato = require('@toa.io/tomato')
|
|
8
8
|
const { io } = require('./io.mock')
|
|
9
|
-
const mock = {
|
|
9
|
+
const mock = { tomato }
|
|
10
10
|
|
|
11
|
-
jest.mock('@cucumber/cucumber', () => mock.
|
|
11
|
+
jest.mock('@cucumber/cucumber', () => mock.tomato)
|
|
12
12
|
|
|
13
13
|
require('../rpc')
|
|
14
14
|
|
|
@@ -24,7 +24,7 @@ beforeEach(() => {
|
|
|
24
24
|
})
|
|
25
25
|
|
|
26
26
|
describe('Given function replying {token} queue:', () => {
|
|
27
|
-
const step =
|
|
27
|
+
const step = tomato.steps.Gi('function replying {token} queue:')
|
|
28
28
|
|
|
29
29
|
it('should be', () => undefined)
|
|
30
30
|
|
|
@@ -43,13 +43,13 @@ describe('Given function replying {token} queue:', () => {
|
|
|
43
43
|
})
|
|
44
44
|
|
|
45
45
|
describe('Given function replying {token} queue is expected:', () => {
|
|
46
|
-
|
|
46
|
+
tomato.steps.Gi('function replying {token} queue is expected:')
|
|
47
47
|
|
|
48
48
|
it('should be', () => undefined)
|
|
49
49
|
})
|
|
50
50
|
|
|
51
51
|
describe('When the consumer sends the following request to the {token} queue:', () => {
|
|
52
|
-
const step =
|
|
52
|
+
const step = tomato.steps.Wh('the consumer sends the following request to the {token} queue:')
|
|
53
53
|
|
|
54
54
|
it('should be', async () => undefined)
|
|
55
55
|
|
|
@@ -90,7 +90,7 @@ describe('When the consumer sends the following request to the {token} queue:',
|
|
|
90
90
|
})
|
|
91
91
|
|
|
92
92
|
describe('When the consumer sends a request to the {token} queue', () => {
|
|
93
|
-
const step =
|
|
93
|
+
const step = tomato.steps.Wh('the consumer sends a request to the {token} queue')
|
|
94
94
|
|
|
95
95
|
it('should be', async () => undefined)
|
|
96
96
|
|
|
@@ -102,7 +102,7 @@ describe('When the consumer sends a request to the {token} queue', () => {
|
|
|
102
102
|
})
|
|
103
103
|
|
|
104
104
|
describe('Then the consumer receives the reply:', () => {
|
|
105
|
-
const step =
|
|
105
|
+
const step = tomato.steps.Th('the consumer receives the reply:')
|
|
106
106
|
|
|
107
107
|
it('should be', async () => undefined)
|
|
108
108
|
|
|
@@ -141,7 +141,7 @@ describe('Then the consumer receives the reply:', () => {
|
|
|
141
141
|
})
|
|
142
142
|
|
|
143
143
|
describe('Then the consumer does not receive the reply', () => {
|
|
144
|
-
const step =
|
|
144
|
+
const step = tomato.steps.Th('the consumer does not receive the reply')
|
|
145
145
|
|
|
146
146
|
it('should be', async () => undefined)
|
|
147
147
|
|
package/features/steps/broker.js
CHANGED
package/lerna.json
ADDED
package/package.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "comq",
|
|
3
|
-
"version": "0.4.0-dev.
|
|
3
|
+
"version": "0.4.0-dev.5",
|
|
4
4
|
"description": "ComQ",
|
|
5
|
-
"homepage": "https://toa.io",
|
|
6
5
|
"author": {
|
|
7
6
|
"name": "Artem Gurtovoi",
|
|
8
7
|
"url": "https://github.com/temich"
|
|
@@ -10,10 +9,10 @@
|
|
|
10
9
|
"license": "MIT",
|
|
11
10
|
"repository": {
|
|
12
11
|
"type": "git",
|
|
13
|
-
"url": "git+https://github.com/toa-io/
|
|
12
|
+
"url": "git+https://github.com/toa-io/comq.git"
|
|
14
13
|
},
|
|
15
14
|
"bugs": {
|
|
16
|
-
"url": "https://github.com/toa-io/
|
|
15
|
+
"url": "https://github.com/toa-io/comq/issues"
|
|
17
16
|
},
|
|
18
17
|
"engines": {
|
|
19
18
|
"node": ">= 12.0.0"
|
|
@@ -24,13 +23,36 @@
|
|
|
24
23
|
"main": "source/index.js",
|
|
25
24
|
"types": "types/index.d.ts",
|
|
26
25
|
"devDependencies": {
|
|
27
|
-
"@
|
|
28
|
-
"@toa.io/
|
|
29
|
-
"@toa.io/
|
|
26
|
+
"@cucumber/cucumber": "9.0.0",
|
|
27
|
+
"@toa.io/command": "0.3.0",
|
|
28
|
+
"@toa.io/mock": "0.3.0",
|
|
29
|
+
"@toa.io/tomato": "0.4.0-dev.2",
|
|
30
|
+
"@toa.io/yaml": "0.4.0-dev.2",
|
|
31
|
+
"@types/amqplib": "0.10.1",
|
|
32
|
+
"@types/jest": "29.4.2",
|
|
33
|
+
"husky": "8.0.3",
|
|
34
|
+
"jest": "29.5.0",
|
|
35
|
+
"randomstring": "1.2.3",
|
|
36
|
+
"snazzy": "9.0.0",
|
|
37
|
+
"standard": "17.0.0"
|
|
30
38
|
},
|
|
31
39
|
"dependencies": {
|
|
32
|
-
"@toa.io/generic": "0.
|
|
40
|
+
"@toa.io/generic": "0.3.0",
|
|
33
41
|
"amqplib": "0.10.3",
|
|
34
42
|
"msgpackr": "1.8.5"
|
|
35
|
-
}
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"prepare": "husky install",
|
|
46
|
+
"test": "npm run lint && jest",
|
|
47
|
+
"test:features": "npx cucumber-js",
|
|
48
|
+
"lint": "npx standard --verbose | npx snazzy"
|
|
49
|
+
},
|
|
50
|
+
"standard": {
|
|
51
|
+
"env": [
|
|
52
|
+
"jest"
|
|
53
|
+
]
|
|
54
|
+
},
|
|
55
|
+
"workspaces": [
|
|
56
|
+
"."
|
|
57
|
+
]
|
|
36
58
|
}
|
package/readme.md
CHANGED
|
@@ -51,7 +51,8 @@ await io.close()
|
|
|
51
51
|
|
|
52
52
|
The following documentation refers to a few terms:
|
|
53
53
|
|
|
54
|
-
**Request** is an AMQP message that has the `replyTo` and `correlationId`
|
|
54
|
+
**Request** is an AMQP message that is sent to a queue and has the `replyTo` and `correlationId`
|
|
55
|
+
properties set.
|
|
55
56
|
|
|
56
57
|
**Reply** is an AMQP message sent in response to a Request and sent to the queue specified in
|
|
57
58
|
the `replyTo` property of the Request. The `correlationId` property of the Reply is set to the same
|
|
@@ -93,7 +94,7 @@ await io.reply('add_numbers', ({ a, b }) => (a + b))
|
|
|
93
94
|
|
|
94
95
|
## Request
|
|
95
96
|
|
|
96
|
-
`async IO.request(queue: string, payload: any, [encoding: string])`
|
|
97
|
+
`async IO.request(queue: string, payload: any, [encoding: string, replyTo: string])`
|
|
97
98
|
|
|
98
99
|
Send encoded Request message with `replyTo` and `correlationId` properties set and
|
|
99
100
|
return decoded Reply content.
|
package/source/io.js
CHANGED
|
@@ -61,13 +61,16 @@ class IO {
|
|
|
61
61
|
* @param {string} queue
|
|
62
62
|
* @param {any} payload
|
|
63
63
|
* @param {comq.encoding} [encoding]
|
|
64
|
+
* @param {string} replyTo
|
|
64
65
|
* @returns {Promise<void>}
|
|
65
66
|
*/
|
|
66
|
-
async (queue, payload, encoding) => {
|
|
67
|
+
async (queue, payload, encoding, replyTo) => {
|
|
67
68
|
const [buffer, contentType] = this.#encode(payload, encoding)
|
|
68
69
|
const correlationId = randomBytes(8).toString('hex')
|
|
69
70
|
const emitter = this.#emitters[queue]
|
|
70
|
-
|
|
71
|
+
|
|
72
|
+
replyTo ??= emitter.queue
|
|
73
|
+
|
|
71
74
|
const properties = { contentType, correlationId, replyTo }
|
|
72
75
|
const reply = this.#createReply()
|
|
73
76
|
|
package/test/io.close.test.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const { randomBytes } = require('node:crypto')
|
|
3
4
|
const { generate } = require('randomstring')
|
|
4
5
|
const { promex, immediate } = require('@toa.io/generic')
|
|
5
6
|
|
|
6
7
|
const mock = require('./connection.mock')
|
|
7
8
|
const { IO } = require('../source/io')
|
|
8
|
-
const { randomBytes } = require('crypto')
|
|
9
9
|
|
|
10
10
|
/** @type {comq.IO} */
|
|
11
11
|
let io
|
package/test/io.reply.test.js
CHANGED
package/test/io.request.test.js
CHANGED
|
@@ -43,6 +43,8 @@ let promise
|
|
|
43
43
|
const REPLY = new RegExp(`^${queue}..[0-9a-f]+$`)
|
|
44
44
|
|
|
45
45
|
beforeEach(async () => {
|
|
46
|
+
jest.clearAllMocks()
|
|
47
|
+
|
|
46
48
|
promise = io.request(queue, payload)
|
|
47
49
|
|
|
48
50
|
// allows initializers to run
|
|
@@ -81,11 +83,36 @@ describe('send', () => {
|
|
|
81
83
|
expect(typeof properties.correlationId).toStrictEqual('string')
|
|
82
84
|
})
|
|
83
85
|
|
|
84
|
-
it('should set replyTo', async () => {
|
|
85
|
-
const
|
|
86
|
+
it('should set default replyTo', async () => {
|
|
87
|
+
const properties = call[2]
|
|
88
|
+
const rx = new RegExp(`^${queue}..[a-z0-9]+`)
|
|
89
|
+
|
|
90
|
+
expect(properties.replyTo).toMatch(rx)
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it('should set specified replyTo', async () => {
|
|
94
|
+
jest.clearAllMocks()
|
|
95
|
+
|
|
96
|
+
/** @type {comq.encoding} */
|
|
97
|
+
const encoding = 'application/json'
|
|
98
|
+
const replyTo = generate()
|
|
99
|
+
|
|
100
|
+
promise = io.request(queue, payload, encoding, replyTo)
|
|
101
|
+
|
|
102
|
+
await immediate()
|
|
103
|
+
|
|
104
|
+
call = requests.send.mock.calls[0]
|
|
105
|
+
|
|
106
|
+
const properties = requests.send.mock.calls[0][2]
|
|
107
|
+
|
|
108
|
+
expect(properties.replyTo).toStrictEqual(replyTo)
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
it('should consume replyTo', async () => {
|
|
112
|
+
const properties = call[2]
|
|
86
113
|
const queue = replies.consume.mock.calls[0][0]
|
|
87
114
|
|
|
88
|
-
expect(
|
|
115
|
+
expect(properties.replyTo).toStrictEqual(queue)
|
|
89
116
|
})
|
|
90
117
|
|
|
91
118
|
it('should encode message with msgpack by default', async () => {
|
package/types/io.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ declare namespace comq {
|
|
|
19
19
|
interface IO {
|
|
20
20
|
reply(queue: string, produce: producer): Promise<void>
|
|
21
21
|
|
|
22
|
-
request(queue: string, payload: any, encoding?: _encoding.encoding): Promise<any>
|
|
22
|
+
request(queue: string, payload: any, encoding?: _encoding.encoding, replyTo?: string): Promise<any>
|
|
23
23
|
|
|
24
24
|
consume(exchange: string, group: string, consumer: consumer): Promise<void>
|
|
25
25
|
|