comq 0.17.0 → 0.17.1

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.
@@ -17,3 +17,9 @@ Feature: Routed events
17
17
  When a message is routed to the `records` exchange under the `placed` key
18
18
  Then `orders` receives the event
19
19
  And `customers` receives nothing
20
+
21
+ Scenario: Routing over a sharded connection
22
+ Given an active sharded connection
23
+ And that `orders` is bound to the `records` exchange under the `placed` key
24
+ When a message is routed to the `records` exchange under the `placed` key
25
+ Then `orders` receives the event
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "comq",
3
- "version": "0.17.0",
3
+ "version": "0.17.1",
4
4
  "description": "ComQ",
5
5
  "author": {
6
6
  "name": "Artem Gurtovoi",
package/readme.md CHANGED
@@ -181,6 +181,9 @@ The queue is named rather than derived from a Consumer group, because what ident
181
181
  the Key it is bound under rather than the exchange it belongs to. It is also durable, so what is
182
182
  published while nothing is consuming is held rather than dropped.
183
183
 
184
+ Over a [sharded connection](#sharded-connection) they behave as the rest does: `route` publishes
185
+ to one shard, and `subscribe` consumes the queue on every one of them.
186
+
184
187
  ### Example
185
188
 
186
189
  ```javascript
@@ -64,6 +64,10 @@ class Channel {
64
64
  await this.#every((channel) => channel.subscribe(queue, group, consumer))
65
65
  }
66
66
 
67
+ async bound (exchange, queue, key, consumer) {
68
+ await this.#every((channel) => channel.bound(exchange, queue, key, consumer))
69
+ }
70
+
67
71
  async send (queue, buffer, options) {
68
72
  await this.#one((channel) => channel.send(queue, buffer, options))
69
73
  }
@@ -72,6 +76,10 @@ class Channel {
72
76
  await this.#one((channel) => channel.publish(exchange, buffer, options))
73
77
  }
74
78
 
79
+ async route (exchange, key, buffer, options) {
80
+ await this.#one((channel) => channel.route(exchange, key, buffer, options))
81
+ }
82
+
75
83
  async fire (queue, buffer, options) {
76
84
  // noinspection JSValidateTypes
77
85
  return await this.#one((channel) => channel.fire(queue, buffer, options))
@@ -718,3 +718,36 @@ async function getCreatedChannels () {
718
718
 
719
719
  return await Promise.all(promises)
720
720
  }
721
+
722
+ describe('routed', () => {
723
+ const exchange = generate()
724
+ const queue = generate()
725
+ const key = generate()
726
+ const buffer = randomBytes(8)
727
+ const consumer = jest.fn()
728
+
729
+ /** @type {jest.MockedObject<comq.Channel>[]} */
730
+ let channels
731
+
732
+ beforeEach(async () => {
733
+ channel = await create(connections, type)
734
+ channels = await getCreatedChannels()
735
+ })
736
+
737
+ it('should bind using all channels', async () => {
738
+ await channel.bound(exchange, queue, key, consumer)
739
+
740
+ for (const chan of channels) {
741
+ expect(chan.bound).toHaveBeenCalledWith(exchange, queue, key, consumer)
742
+ }
743
+ })
744
+
745
+ it('should route to a single channel', async () => {
746
+ await channel.route(exchange, key, buffer)
747
+
748
+ const used = channels.filter((chan) => chan.route.mock.calls.length > 0)
749
+
750
+ expect(used).toHaveLength(1)
751
+ expect(used[0].route).toHaveBeenCalledWith(exchange, key, buffer, undefined)
752
+ })
753
+ })