message_bus 4.1.0 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 11a14ba0ec9ad142d3335fb7eb764be8e9b975a8dc8367fd4bf359e128a56095
4
- data.tar.gz: bf41cede85c8e75e56829447cd3cf9ed6cd531ba27fcddfbccb6043f3a82da34
3
+ metadata.gz: f725f70ad14bdd643aea469118faba0c666f36c47ec6fc3b33dc3c2db85ee8fb
4
+ data.tar.gz: faf76a2ef12077e48890250b60572700076d0d9da317df2f91d96d49f514e002
5
5
  SHA512:
6
- metadata.gz: 23c1d181028194c16e98c5a3df42e445458aef4779c97ae2d6d5100adf5053680f62ea4c914bea7c84c124bd453127e141c68ffeb1c742cc208e1d040bc8558f
7
- data.tar.gz: 7efffe711fac2520356b115820acba2d4206d53f35017ba64c86e3c571a85fb423e943cb9301a03d3b47d6f442f1626dea0495c0242220283685eaa944c890b6
6
+ metadata.gz: a73153925e4bd93e5dcc2b8d09c18b944f074bcac7b9de563923e7ac3abd0552951f89418f09d58682fa41748810491cb3e6cfbc24fef1c6f32c7b397724e8a5
7
+ data.tar.gz: 659ebc5f7c22af1ab1dbd23247896e51511394bdad062816bb25174f1fc5d8d474171fc4d8d2a7e989f2a6eda700e4fe38b8caa7bf575a70319e5d318ee18f9f
@@ -43,7 +43,7 @@ jobs:
43
43
  --health-retries 5
44
44
 
45
45
  steps:
46
- - uses: actions/checkout@v2
46
+ - uses: actions/checkout@v3
47
47
 
48
48
  - uses: ruby/setup-ruby@v1
49
49
  with:
@@ -51,9 +51,9 @@ jobs:
51
51
  bundler-cache: true
52
52
 
53
53
  - name: Set up Node.js
54
- uses: actions/setup-node@v2
54
+ uses: actions/setup-node@v3
55
55
  with:
56
- node-version: 16
56
+ node-version: 18
57
57
  cache: npm
58
58
 
59
59
  - name: Setup npm
@@ -74,7 +74,7 @@ jobs:
74
74
  runs-on: ubuntu-latest
75
75
 
76
76
  steps:
77
- - uses: actions/checkout@v2
77
+ - uses: actions/checkout@v3
78
78
 
79
79
  - name: Release gem
80
80
  uses: discourse/publish-rubygems-action@v2
data/CHANGELOG CHANGED
@@ -1,3 +1,20 @@
1
+ FUTURE
2
+
3
+ 04-11-2022
4
+
5
+ - Version 4.2.0
6
+
7
+ - FIX: Add redis gem version 5 support
8
+ - FEATURE: Allow disabling subscriptions without disabling publication
9
+
10
+ 22-02-2022
11
+
12
+ - Version 4.2.0
13
+
14
+ - FEATURE: Add support for `clear_every` parameter in Redis backend
15
+
16
+ This allows the clearing of the backlog to take place once every N messages. In high-load scenarios, this can provide significant performance benefit.
17
+
1
18
  16-02-2022
2
19
 
3
20
  - Version 4.1.0
@@ -368,6 +385,7 @@
368
385
 
369
386
  - Version 2.0.0.beta.5
370
387
 
388
+ - Feature: Memory backend @jeremyevans
371
389
  - Fix: JavaScript unsubscribe was not updating publicly visible MessageBus.callbacks @sam
372
390
  - Fix: When MessageBus is talking to a readonly redis buffering may cause a infinite loop @tgxworld
373
391
 
data/Dockerfile CHANGED
@@ -1,4 +1,4 @@
1
- FROM ruby:2.5
1
+ FROM ruby:2.7
2
2
 
3
3
  RUN cd /tmp && \
4
4
  wget --quiet https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2 && \
@@ -10,7 +10,7 @@ WORKDIR /usr/src/app
10
10
 
11
11
  RUN mkdir -p ./lib/message_bus
12
12
  COPY lib/message_bus/version.rb ./lib/message_bus
13
- COPY Gemfile Gemfile.lock *.gemspec ./
13
+ COPY Gemfile *.gemspec ./
14
14
  RUN bundle install
15
15
 
16
16
  COPY . .
data/README.md CHANGED
@@ -155,7 +155,7 @@ end)
155
155
 
156
156
  #### Disabling message_bus
157
157
 
158
- In certain cases, it is undesirable for message_bus to start up on application start, for example in a Rails application during the `db:create` rake task when using the Postgres backend (which will error trying to connect to the non-existent database to subscribe). You can invoke `MessageBus.off` before the middleware chain is loaded in order to prevent subscriptions and publications from happening; in a Rails app you might do this in an initializer based on some environment variable or some other conditional means.
158
+ In certain cases, it is undesirable for message_bus to start up on application start, for example in a Rails application during the `db:create` rake task when using the Postgres backend (which will error trying to connect to the non-existent database to subscribe). You can invoke `MessageBus.off` before the middleware chain is loaded in order to prevent subscriptions and publications from happening; in a Rails app you might do this in an initializer based on some environment variable or some other conditional means. If you want to just disable subscribing to the bus but want to continue to allow publications to be made, you can do `MessageBus.off(disable_publish: false)`.
159
159
 
160
160
  ### Debugging
161
161
 
@@ -388,7 +388,9 @@ The redis client message_bus uses is [redis-rb](https://github.com/redis/redis-r
388
388
 
389
389
  #### Data Retention
390
390
 
391
- Out of the box Redis keeps track of 2000 messages in the global backlog and 1000 messages in a per-channel backlog. Per-channel backlogs get cleared automatically after 7 days of inactivity.
391
+ Out of the box Redis keeps track of 2000 messages in the global backlog and 1000 messages in a per-channel backlog. Per-channel backlogs get
392
+ cleared automatically after 7 days of inactivity. By default, the backlog will be pruned on every message publication. If exact backlog
393
+ length limiting is not required, the `clear_every` parameter can be set higher to improve performance.
392
394
 
393
395
  This is configurable via accessors on the Backend instance.
394
396
 
@@ -401,6 +403,9 @@ MessageBus.backend_instance.max_global_backlog_size = 100
401
403
 
402
404
  # flush per-channel backlog after 100 seconds of inactivity
403
405
  MessageBus.backend_instance.max_backlog_age = 100
406
+
407
+ # clear the backlog every 50 messages
408
+ MessageBus.backend_instance.clear_every = 50
404
409
  ```
405
410
 
406
411
  ### PostgreSQL
@@ -423,7 +428,7 @@ message_bus also supports an in-memory backend. This can be used for testing or
423
428
  MessageBus.configure(backend: :memory)
424
429
  ```
425
430
 
426
- The `:clear_every` option supported by the PostgreSQL backend is also supported by the in-memory backend.
431
+ The `:clear_every` option is supported in the same way as the PostgreSQL backend.
427
432
 
428
433
  ### Transport codecs
429
434
 
@@ -30,8 +30,6 @@ module MessageBus
30
30
  # messages are removed (when no publication happens during this
31
31
  # time-frame).
32
32
  #
33
- # * `clear_every` is not a supported option for this backend.
34
- #
35
33
  # @see Base general information about message_bus backends
36
34
  class Redis < Base
37
35
  class BackLogOutOfOrder < StandardError
@@ -45,9 +43,11 @@ module MessageBus
45
43
  # @param [Hash] redis_config in addition to the options listed, see https://github.com/redis/redis-rb for other available options
46
44
  # @option redis_config [Logger] :logger a logger to which logs will be output
47
45
  # @option redis_config [Boolean] :enable_redis_logger (false) whether or not to enable logging by the underlying Redis library
46
+ # @option redis_config [Integer] :clear_every (1) the interval of publications between which the backlog will not be cleared
48
47
  # @param [Integer] max_backlog_size the largest permitted size (number of messages) for per-channel backlogs; beyond this capacity, old messages will be dropped.
49
48
  def initialize(redis_config = {}, max_backlog_size = 1000)
50
49
  @redis_config = redis_config.dup
50
+ @clear_every = redis_config.delete(:clear_every) || 1
51
51
  @logger = @redis_config[:logger]
52
52
  unless @redis_config[:enable_redis_logger]
53
53
  @redis_config[:logger] = nil
@@ -100,6 +100,7 @@ module MessageBus
100
100
  local max_backlog_size = tonumber(ARGV[3])
101
101
  local max_global_backlog_size = tonumber(ARGV[4])
102
102
  local channel = ARGV[5]
103
+ local clear_every = ARGV[6]
103
104
 
104
105
  local global_id_key = KEYS[1]
105
106
  local backlog_id_key = KEYS[2]
@@ -120,11 +121,11 @@ module MessageBus
120
121
 
121
122
  redis.call("EXPIRE", backlog_id_key, max_backlog_age)
122
123
 
123
- if backlog_id > max_backlog_size then
124
+ if backlog_id > max_backlog_size and backlog_id % clear_every == 0 then
124
125
  redis.call("ZREMRANGEBYSCORE", backlog_key, 1, backlog_id - max_backlog_size)
125
126
  end
126
127
 
127
- if global_id > max_global_backlog_size then
128
+ if global_id > max_global_backlog_size and global_id % clear_every == 0 then
128
129
  redis.call("ZREMRANGEBYSCORE", global_backlog_key, 1, global_id - max_global_backlog_size)
129
130
  end
130
131
 
@@ -155,7 +156,8 @@ LUA
155
156
  max_backlog_age,
156
157
  max_backlog_size,
157
158
  max_global_backlog_size,
158
- channel
159
+ channel,
160
+ clear_every
159
161
  ],
160
162
  keys: [
161
163
  global_id_key,
@@ -344,7 +346,29 @@ LUA
344
346
  private
345
347
 
346
348
  def new_redis_connection
347
- ::Redis.new(@redis_config.dup)
349
+ config = @redis_config.filter do |k, v|
350
+ # This is not ideal, required for Redis gem version 5
351
+ # redis-client no longer accepts arbitrary params
352
+ # anything unknown will error out.
353
+ # https://github.com/redis-rb/redis-client/blob/4c8e05acfb3477c1651138a4924616e79e6116f2/lib/redis_client/config.rb#L21-L39
354
+ #
355
+ #
356
+ # We should be doing the opposite and allowlisting params
357
+ # or splitting the object up. Starting with the smallest change that is backwards compatible
358
+ ![
359
+ :backend,
360
+ :logger,
361
+ :long_polling_enabled,
362
+ :backend_options,
363
+ :base_route,
364
+ :client_message_filters,
365
+ :site_id_lookup,
366
+ :group_id_lookup,
367
+ :user_id_lookup,
368
+ :transport_codec
369
+ ].include?(k)
370
+ end
371
+ ::Redis.new(config)
348
372
  end
349
373
 
350
374
  # redis connection used for publishing messages
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MessageBus
4
- VERSION = "4.1.0"
4
+ VERSION = "4.3.0"
5
5
  end
data/lib/message_bus.rb CHANGED
@@ -40,6 +40,7 @@ module MessageBus::Implementation
40
40
  @config = {}
41
41
  @mutex = Synchronizer.new
42
42
  @off = false
43
+ @off_disable_publish = false
43
44
  @destroyed = false
44
45
  @timer_thread = nil
45
46
  @subscriber_thread = nil
@@ -160,15 +161,17 @@ module MessageBus::Implementation
160
161
  end
161
162
 
162
163
  # Disables publication to the bus
164
+ # @param [Boolean] disable_publish Whether or not to disable publishing
163
165
  # @return [void]
164
- def off
166
+ def off(disable_publish: true)
165
167
  @off = true
168
+ @off_disable_publish = disable_publish
166
169
  end
167
170
 
168
171
  # Enables publication to the bus
169
172
  # @return [void]
170
173
  def on
171
- @destroyed = @off = false
174
+ @destroyed = @off = @off_disable_publish = false
172
175
  end
173
176
 
174
177
  # Overrides existing configuration
@@ -338,7 +341,7 @@ module MessageBus::Implementation
338
341
  # @raise [MessageBus::InvalidMessage] if attempting to put permission restrictions on a globally-published message
339
342
  # @raise [MessageBus::InvalidMessageTarget] if attempting to publish to a empty group of users
340
343
  def publish(channel, data, opts = nil)
341
- return if @off
344
+ return if @off_disable_publish
342
345
 
343
346
  @mutex.synchronize do
344
347
  raise ::MessageBus::BusDestroyed if @destroyed
@@ -664,6 +667,8 @@ module MessageBus::Implementation
664
667
  end
665
668
 
666
669
  def subscribe_impl(channel, site_id, last_id, &blk)
670
+ return if @off
671
+
667
672
  raise MessageBus::BusDestroyed if @destroyed
668
673
 
669
674
  if last_id >= 0
data/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "message-bus-client",
3
- "version": "3.3.5",
3
+ "version": "0.0.0-version-placeholder",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "message-bus-client",
9
- "version": "3.3.5",
9
+ "version": "0.0.0-version-placeholder",
10
10
  "license": "MIT",
11
11
  "devDependencies": {
12
12
  "eslint": "^7.27.0",
@@ -215,9 +215,9 @@
215
215
  }
216
216
  },
217
217
  "node_modules/ansi-regex": {
218
- "version": "5.0.0",
219
- "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz",
220
- "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==",
218
+ "version": "5.0.1",
219
+ "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
220
+ "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
221
221
  "dev": true,
222
222
  "engines": {
223
223
  "node": ">=8"
@@ -263,9 +263,9 @@
263
263
  }
264
264
  },
265
265
  "node_modules/async": {
266
- "version": "0.9.2",
267
- "resolved": "https://registry.npmjs.org/async/-/async-0.9.2.tgz",
268
- "integrity": "sha1-rqdNXmHB+JlhO/ZL2mbUx48v0X0=",
266
+ "version": "3.2.3",
267
+ "resolved": "https://registry.npmjs.org/async/-/async-3.2.3.tgz",
268
+ "integrity": "sha512-spZRyzKL5l5BZQrr/6m/SqFdBN0q3OCI0f9rjfBzCMBIP4p75P620rR3gTmaksNOhmzgdxcaxdNfMy6anrbM0g==",
269
269
  "dev": true
270
270
  },
271
271
  "node_modules/balanced-match": {
@@ -491,12 +491,12 @@
491
491
  "dev": true
492
492
  },
493
493
  "node_modules/ejs": {
494
- "version": "3.1.6",
495
- "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.6.tgz",
496
- "integrity": "sha512-9lt9Zse4hPucPkoP7FHDF0LQAlGyF9JVpnClFLFH3aSSbxmyoqINRpp/9wePWJTUl4KOQwRL72Iw3InHPDkoGw==",
494
+ "version": "3.1.8",
495
+ "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.8.tgz",
496
+ "integrity": "sha512-/sXZeMlhS0ArkfX2Aw780gJzXSMPnKjtspYZv+f3NiKLlubezAHDU5+9xz6gd3/NhG3txQCo6xlglmTS+oTGEQ==",
497
497
  "dev": true,
498
498
  "dependencies": {
499
- "jake": "^10.6.1"
499
+ "jake": "^10.8.5"
500
500
  },
501
501
  "bin": {
502
502
  "ejs": "bin/cli.js"
@@ -844,12 +844,33 @@
844
844
  }
845
845
  },
846
846
  "node_modules/filelist": {
847
- "version": "1.0.2",
848
- "resolved": "https://registry.npmjs.org/filelist/-/filelist-1.0.2.tgz",
849
- "integrity": "sha512-z7O0IS8Plc39rTCq6i6iHxk43duYOn8uFJiWSewIq0Bww1RNybVHSCjahmcC87ZqAm4OTvFzlzeGu3XAzG1ctQ==",
847
+ "version": "1.0.4",
848
+ "resolved": "https://registry.npmjs.org/filelist/-/filelist-1.0.4.tgz",
849
+ "integrity": "sha512-w1cEuf3S+DrLCQL7ET6kz+gmlJdbq9J7yXCSjK/OZCPA+qEN1WyF4ZAf0YYJa4/shHJra2t/d/r8SV4Ji+x+8Q==",
850
850
  "dev": true,
851
851
  "dependencies": {
852
- "minimatch": "^3.0.4"
852
+ "minimatch": "^5.0.1"
853
+ }
854
+ },
855
+ "node_modules/filelist/node_modules/brace-expansion": {
856
+ "version": "2.0.1",
857
+ "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz",
858
+ "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==",
859
+ "dev": true,
860
+ "dependencies": {
861
+ "balanced-match": "^1.0.0"
862
+ }
863
+ },
864
+ "node_modules/filelist/node_modules/minimatch": {
865
+ "version": "5.0.1",
866
+ "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.0.1.tgz",
867
+ "integrity": "sha512-nLDxIFRyhDblz3qMuq+SoRZED4+miJ/G+tdDrjkkkRnjAsBexeGpgjLEQ0blJy7rHhR2b93rhQY4SvyWu9v03g==",
868
+ "dev": true,
869
+ "dependencies": {
870
+ "brace-expansion": "^2.0.1"
871
+ },
872
+ "engines": {
873
+ "node": ">=10"
853
874
  }
854
875
  },
855
876
  "node_modules/finalhandler": {
@@ -1132,13 +1153,13 @@
1132
1153
  "dev": true
1133
1154
  },
1134
1155
  "node_modules/jake": {
1135
- "version": "10.8.2",
1136
- "resolved": "https://registry.npmjs.org/jake/-/jake-10.8.2.tgz",
1137
- "integrity": "sha512-eLpKyrfG3mzvGE2Du8VoPbeSkRry093+tyNjdYaBbJS9v17knImYGNXQCUV0gLxQtF82m3E8iRb/wdSQZLoq7A==",
1156
+ "version": "10.8.5",
1157
+ "resolved": "https://registry.npmjs.org/jake/-/jake-10.8.5.tgz",
1158
+ "integrity": "sha512-sVpxYeuAhWt0OTWITwT98oyV0GsXyMlXCF+3L1SuafBVUIr/uILGRB+NqwkzhgXKvoJpDIpQvqkUALgdmQsQxw==",
1138
1159
  "dev": true,
1139
1160
  "dependencies": {
1140
- "async": "0.9.x",
1141
- "chalk": "^2.4.2",
1161
+ "async": "^3.2.3",
1162
+ "chalk": "^4.0.2",
1142
1163
  "filelist": "^1.0.1",
1143
1164
  "minimatch": "^3.0.4"
1144
1165
  },
@@ -1146,78 +1167,7 @@
1146
1167
  "jake": "bin/cli.js"
1147
1168
  },
1148
1169
  "engines": {
1149
- "node": "*"
1150
- }
1151
- },
1152
- "node_modules/jake/node_modules/ansi-styles": {
1153
- "version": "3.2.1",
1154
- "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
1155
- "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
1156
- "dev": true,
1157
- "dependencies": {
1158
- "color-convert": "^1.9.0"
1159
- },
1160
- "engines": {
1161
- "node": ">=4"
1162
- }
1163
- },
1164
- "node_modules/jake/node_modules/chalk": {
1165
- "version": "2.4.2",
1166
- "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
1167
- "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
1168
- "dev": true,
1169
- "dependencies": {
1170
- "ansi-styles": "^3.2.1",
1171
- "escape-string-regexp": "^1.0.5",
1172
- "supports-color": "^5.3.0"
1173
- },
1174
- "engines": {
1175
- "node": ">=4"
1176
- }
1177
- },
1178
- "node_modules/jake/node_modules/color-convert": {
1179
- "version": "1.9.3",
1180
- "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
1181
- "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==",
1182
- "dev": true,
1183
- "dependencies": {
1184
- "color-name": "1.1.3"
1185
- }
1186
- },
1187
- "node_modules/jake/node_modules/color-name": {
1188
- "version": "1.1.3",
1189
- "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
1190
- "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=",
1191
- "dev": true
1192
- },
1193
- "node_modules/jake/node_modules/escape-string-regexp": {
1194
- "version": "1.0.5",
1195
- "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
1196
- "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=",
1197
- "dev": true,
1198
- "engines": {
1199
- "node": ">=0.8.0"
1200
- }
1201
- },
1202
- "node_modules/jake/node_modules/has-flag": {
1203
- "version": "3.0.0",
1204
- "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
1205
- "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=",
1206
- "dev": true,
1207
- "engines": {
1208
- "node": ">=4"
1209
- }
1210
- },
1211
- "node_modules/jake/node_modules/supports-color": {
1212
- "version": "5.5.0",
1213
- "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
1214
- "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
1215
- "dev": true,
1216
- "dependencies": {
1217
- "has-flag": "^3.0.0"
1218
- },
1219
- "engines": {
1220
- "node": ">=4"
1170
+ "node": ">=10"
1221
1171
  }
1222
1172
  },
1223
1173
  "node_modules/jasmine-browser-runner": {
@@ -2258,9 +2208,9 @@
2258
2208
  "dev": true
2259
2209
  },
2260
2210
  "ansi-regex": {
2261
- "version": "5.0.0",
2262
- "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz",
2263
- "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==",
2211
+ "version": "5.0.1",
2212
+ "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
2213
+ "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
2264
2214
  "dev": true
2265
2215
  },
2266
2216
  "ansi-styles": {
@@ -2294,9 +2244,9 @@
2294
2244
  "dev": true
2295
2245
  },
2296
2246
  "async": {
2297
- "version": "0.9.2",
2298
- "resolved": "https://registry.npmjs.org/async/-/async-0.9.2.tgz",
2299
- "integrity": "sha1-rqdNXmHB+JlhO/ZL2mbUx48v0X0=",
2247
+ "version": "3.2.3",
2248
+ "resolved": "https://registry.npmjs.org/async/-/async-3.2.3.tgz",
2249
+ "integrity": "sha512-spZRyzKL5l5BZQrr/6m/SqFdBN0q3OCI0f9rjfBzCMBIP4p75P620rR3gTmaksNOhmzgdxcaxdNfMy6anrbM0g==",
2300
2250
  "dev": true
2301
2251
  },
2302
2252
  "balanced-match": {
@@ -2480,12 +2430,12 @@
2480
2430
  "dev": true
2481
2431
  },
2482
2432
  "ejs": {
2483
- "version": "3.1.6",
2484
- "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.6.tgz",
2485
- "integrity": "sha512-9lt9Zse4hPucPkoP7FHDF0LQAlGyF9JVpnClFLFH3aSSbxmyoqINRpp/9wePWJTUl4KOQwRL72Iw3InHPDkoGw==",
2433
+ "version": "3.1.8",
2434
+ "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.8.tgz",
2435
+ "integrity": "sha512-/sXZeMlhS0ArkfX2Aw780gJzXSMPnKjtspYZv+f3NiKLlubezAHDU5+9xz6gd3/NhG3txQCo6xlglmTS+oTGEQ==",
2486
2436
  "dev": true,
2487
2437
  "requires": {
2488
- "jake": "^10.6.1"
2438
+ "jake": "^10.8.5"
2489
2439
  }
2490
2440
  },
2491
2441
  "emoji-regex": {
@@ -2761,12 +2711,32 @@
2761
2711
  }
2762
2712
  },
2763
2713
  "filelist": {
2764
- "version": "1.0.2",
2765
- "resolved": "https://registry.npmjs.org/filelist/-/filelist-1.0.2.tgz",
2766
- "integrity": "sha512-z7O0IS8Plc39rTCq6i6iHxk43duYOn8uFJiWSewIq0Bww1RNybVHSCjahmcC87ZqAm4OTvFzlzeGu3XAzG1ctQ==",
2714
+ "version": "1.0.4",
2715
+ "resolved": "https://registry.npmjs.org/filelist/-/filelist-1.0.4.tgz",
2716
+ "integrity": "sha512-w1cEuf3S+DrLCQL7ET6kz+gmlJdbq9J7yXCSjK/OZCPA+qEN1WyF4ZAf0YYJa4/shHJra2t/d/r8SV4Ji+x+8Q==",
2767
2717
  "dev": true,
2768
2718
  "requires": {
2769
- "minimatch": "^3.0.4"
2719
+ "minimatch": "^5.0.1"
2720
+ },
2721
+ "dependencies": {
2722
+ "brace-expansion": {
2723
+ "version": "2.0.1",
2724
+ "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz",
2725
+ "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==",
2726
+ "dev": true,
2727
+ "requires": {
2728
+ "balanced-match": "^1.0.0"
2729
+ }
2730
+ },
2731
+ "minimatch": {
2732
+ "version": "5.0.1",
2733
+ "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.0.1.tgz",
2734
+ "integrity": "sha512-nLDxIFRyhDblz3qMuq+SoRZED4+miJ/G+tdDrjkkkRnjAsBexeGpgjLEQ0blJy7rHhR2b93rhQY4SvyWu9v03g==",
2735
+ "dev": true,
2736
+ "requires": {
2737
+ "brace-expansion": "^2.0.1"
2738
+ }
2739
+ }
2770
2740
  }
2771
2741
  },
2772
2742
  "finalhandler": {
@@ -2993,73 +2963,15 @@
2993
2963
  "dev": true
2994
2964
  },
2995
2965
  "jake": {
2996
- "version": "10.8.2",
2997
- "resolved": "https://registry.npmjs.org/jake/-/jake-10.8.2.tgz",
2998
- "integrity": "sha512-eLpKyrfG3mzvGE2Du8VoPbeSkRry093+tyNjdYaBbJS9v17knImYGNXQCUV0gLxQtF82m3E8iRb/wdSQZLoq7A==",
2966
+ "version": "10.8.5",
2967
+ "resolved": "https://registry.npmjs.org/jake/-/jake-10.8.5.tgz",
2968
+ "integrity": "sha512-sVpxYeuAhWt0OTWITwT98oyV0GsXyMlXCF+3L1SuafBVUIr/uILGRB+NqwkzhgXKvoJpDIpQvqkUALgdmQsQxw==",
2999
2969
  "dev": true,
3000
2970
  "requires": {
3001
- "async": "0.9.x",
3002
- "chalk": "^2.4.2",
2971
+ "async": "^3.2.3",
2972
+ "chalk": "^4.0.2",
3003
2973
  "filelist": "^1.0.1",
3004
2974
  "minimatch": "^3.0.4"
3005
- },
3006
- "dependencies": {
3007
- "ansi-styles": {
3008
- "version": "3.2.1",
3009
- "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
3010
- "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
3011
- "dev": true,
3012
- "requires": {
3013
- "color-convert": "^1.9.0"
3014
- }
3015
- },
3016
- "chalk": {
3017
- "version": "2.4.2",
3018
- "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
3019
- "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
3020
- "dev": true,
3021
- "requires": {
3022
- "ansi-styles": "^3.2.1",
3023
- "escape-string-regexp": "^1.0.5",
3024
- "supports-color": "^5.3.0"
3025
- }
3026
- },
3027
- "color-convert": {
3028
- "version": "1.9.3",
3029
- "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
3030
- "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==",
3031
- "dev": true,
3032
- "requires": {
3033
- "color-name": "1.1.3"
3034
- }
3035
- },
3036
- "color-name": {
3037
- "version": "1.1.3",
3038
- "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
3039
- "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=",
3040
- "dev": true
3041
- },
3042
- "escape-string-regexp": {
3043
- "version": "1.0.5",
3044
- "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
3045
- "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=",
3046
- "dev": true
3047
- },
3048
- "has-flag": {
3049
- "version": "3.0.0",
3050
- "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
3051
- "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=",
3052
- "dev": true
3053
- },
3054
- "supports-color": {
3055
- "version": "5.5.0",
3056
- "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
3057
- "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
3058
- "dev": true,
3059
- "requires": {
3060
- "has-flag": "^3.0.0"
3061
- }
3062
- }
3063
2975
  }
3064
2976
  },
3065
2977
  "jasmine-browser-runner": {
@@ -310,8 +310,6 @@ describe BACKEND_CLASS do
310
310
  end
311
311
 
312
312
  it "should support clear_every setting" do
313
- test_never :redis
314
-
315
313
  @bus.clear_every = 5
316
314
  @bus.max_global_backlog_size = 2
317
315
  @bus.publish "/foo", "11"
@@ -394,11 +392,4 @@ describe BACKEND_CLASS do
394
392
  got.map { |m| m.data }.must_equal ["12"]
395
393
  end
396
394
 
397
- it 'should not lose redis config' do
398
- test_only :redis
399
- redis_config = { connector: Redis::Client::Connector }
400
- @bus.instance_variable_set(:@redis_config, redis_config)
401
- @bus.send(:new_redis_connection)
402
- expect(@bus.instance_variable_get(:@redis_config)[:connector]).must_equal Redis::Client::Connector
403
- end
404
395
  end
@@ -17,26 +17,6 @@ describe MessageBus do
17
17
  @bus.destroy
18
18
  end
19
19
 
20
- it "can be turned off" do
21
- @bus.off
22
-
23
- @bus.off?.must_equal true
24
- end
25
-
26
- it "can call destroy multiple times" do
27
- @bus.destroy
28
- @bus.destroy
29
- @bus.destroy
30
- end
31
-
32
- it "can be turned on after destroy" do
33
- @bus.destroy
34
-
35
- @bus.on
36
-
37
- @bus.after_fork
38
- end
39
-
40
20
  it "destroying immediately after `after_fork` does not lock" do
41
21
  10.times do
42
22
  @bus.on
@@ -216,6 +196,58 @@ describe MessageBus do
216
196
  @bus.backlog("/chuck").map { |i| i.data }.to_a.must_equal ['foo']
217
197
  end
218
198
 
199
+ it "can be turned off" do
200
+ @bus.off
201
+
202
+ @bus.off?.must_equal true
203
+
204
+ @bus.publish("/chuck", "norris")
205
+
206
+ @bus.backlog("/chuck").to_a.must_equal []
207
+ end
208
+
209
+ it "can be turned off only for subscriptions" do
210
+ @bus.off(disable_publish: false)
211
+
212
+ @bus.off?.must_equal true
213
+
214
+ data = []
215
+
216
+ @bus.subscribe("/chuck") do |msg|
217
+ data << msg.data
218
+ end
219
+
220
+ @bus.publish("/chuck", "norris")
221
+
222
+ @bus.on
223
+
224
+ @bus.subscribe("/chuck") do |msg|
225
+ data << msg.data
226
+ end
227
+
228
+ @bus.publish("/chuck", "berry")
229
+
230
+ wait_for(2000) { data.length > 0 }
231
+
232
+ data.must_equal ["berry"]
233
+
234
+ @bus.backlog("/chuck").map(&:data).to_a.must_equal ["norris", "berry"]
235
+ end
236
+
237
+ it "can call destroy multiple times" do
238
+ @bus.destroy
239
+ @bus.destroy
240
+ @bus.destroy
241
+ end
242
+
243
+ it "can be turned on after destroy" do
244
+ @bus.destroy
245
+
246
+ @bus.on
247
+
248
+ @bus.after_fork
249
+ end
250
+
219
251
  it "allows you to look up last_message" do
220
252
  @bus.publish("/bob", "dylan")
221
253
  @bus.publish("/bob", "marley")
@@ -9,7 +9,7 @@ require_relative "../helpers"
9
9
 
10
10
  backends = ENV['MESSAGE_BUS_BACKENDS'].split(",").map(&:to_sym)
11
11
  channel = "/foo"
12
- iterations = 10_000
12
+ iterations = 100_000
13
13
  results = []
14
14
 
15
15
  puts "Running publication benchmark with #{iterations} iterations on backends: #{backends.inspect}"
@@ -78,6 +78,33 @@ benchmark_subscription_with_trimming = lambda do |bm, backend|
78
78
  bus.destroy
79
79
  end
80
80
 
81
+ benchmark_subscription_with_trimming_and_clear_every = lambda do |bm, backend|
82
+ test_title = "#{backend} - subscription with trimming and clear_every=50"
83
+
84
+ bus = MessageBus::Instance.new
85
+ bus.configure(test_config_for_backend(backend))
86
+
87
+ bus.backend_instance.max_backlog_size = (iterations / 10)
88
+ bus.backend_instance.max_global_backlog_size = (iterations / 10)
89
+ bus.backend_instance.clear_every = 50
90
+
91
+ messages_received = 0
92
+ bus.after_fork
93
+ bus.subscribe(channel) do |_message|
94
+ messages_received += 1
95
+ end
96
+
97
+ bm.report(test_title) do
98
+ iterations.times { bus.publish(channel, "Hello world") }
99
+ wait_for(60000) { messages_received == iterations }
100
+ end
101
+
102
+ results << "[#{test_title}]: #{iterations} messages sent, #{messages_received} received, rate of #{(messages_received.to_f / iterations.to_f) * 100}%"
103
+
104
+ bus.reset!
105
+ bus.destroy
106
+ end
107
+
81
108
  puts
82
109
  Benchmark.bm(60) do |bm|
83
110
  backends.each do |backend|
@@ -96,6 +123,10 @@ Benchmark.bm(60) do |bm|
96
123
  backends.each do |backend|
97
124
  benchmark_subscription_with_trimming.call(bm, backend)
98
125
  end
126
+
127
+ backends.each do |backend|
128
+ benchmark_subscription_with_trimming_and_clear_every.call(bm, backend)
129
+ end
99
130
  end
100
131
  puts
101
132
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: message_bus
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ version: 4.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-17 00:00:00.000000000 Z
11
+ date: 2022-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack