message_bus 3.3.8 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.eslintrc.js +1 -8
- data/.github/workflows/ci.yml +3 -1
- data/CHANGELOG +107 -46
- data/README.md +38 -55
- data/Rakefile +22 -22
- data/docker-compose.yml +1 -1
- data/lib/message_bus/backends/base.rb +9 -0
- data/lib/message_bus/backends/memory.rb +7 -0
- data/lib/message_bus/backends/postgres.rb +35 -9
- data/lib/message_bus/backends/redis.rb +18 -5
- data/lib/message_bus/client.rb +23 -22
- data/lib/message_bus/rack/middleware.rb +0 -6
- data/lib/message_bus/version.rb +1 -1
- data/lib/message_bus.rb +49 -72
- data/message_bus.gemspec +0 -2
- data/spec/lib/message_bus/backend_spec.rb +19 -5
- data/spec/lib/message_bus/multi_process_spec.rb +3 -2
- data/spec/lib/message_bus/rack/middleware_spec.rb +0 -48
- data/spec/lib/message_bus/timer_thread_spec.rb +1 -5
- data/spec/lib/message_bus_spec.rb +10 -2
- data/spec/performance/backlog.rb +80 -0
- data/spec/performance/publish.rb +36 -5
- data/spec/spec_helper.rb +1 -1
- metadata +4 -30
- data/assets/application.jsx +0 -121
- data/assets/babel.min.js +0 -25
- data/assets/react-dom.js +0 -19851
- data/assets/react.js +0 -3029
- data/examples/diagnostics/Gemfile +0 -6
- data/examples/diagnostics/config.ru +0 -22
- data/lib/message_bus/diagnostics.rb +0 -62
- data/lib/message_bus/rack/diagnostics.rb +0 -120
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: edad2fa285f65718a34893791166991c2cdf893b6e7064c5163882cd92f5fc95
|
4
|
+
data.tar.gz: 686c4fcc4c02add5adf75fa08586491af36173d67bfac917093b291d8d3343f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb23eadc6112f7d28128b46e1e00d7bbdd196cf574398a3746927210d9affd4f127b83e6a9f104a65d8909d03729af16221ef7ec159126cdc5208d6eacf3e2d5
|
7
|
+
data.tar.gz: bdbf6a4d6d3c129f58a8c0fb02d5275cda59becb59120a602423340597e7afcb84410b39f58b537a2962a0157d0a1ca10d2efbc28f6bfbea4e3fe160a7cf46f7
|
data/.eslintrc.js
CHANGED
@@ -10,12 +10,5 @@ module.exports = {
|
|
10
10
|
sourceType: 'module',
|
11
11
|
},
|
12
12
|
rules: {},
|
13
|
-
ignorePatterns: [
|
14
|
-
'/vendor',
|
15
|
-
'/doc',
|
16
|
-
'/assets/babel.min.js',
|
17
|
-
'/assets/jquery-1.8.2.js',
|
18
|
-
'/assets/react-dom.js',
|
19
|
-
'/assets/react.js',
|
20
|
-
],
|
13
|
+
ignorePatterns: ['/vendor', '/doc', '/assets/jquery-1.8.2.js'],
|
21
14
|
};
|
data/.github/workflows/ci.yml
CHANGED
@@ -20,7 +20,7 @@ jobs:
|
|
20
20
|
strategy:
|
21
21
|
fail-fast: false
|
22
22
|
matrix:
|
23
|
-
ruby: [2.6, 2.7, 3.0]
|
23
|
+
ruby: [2.6, 2.7, '3.0', 3.1]
|
24
24
|
redis: [5, 6]
|
25
25
|
|
26
26
|
services:
|
@@ -60,6 +60,8 @@ jobs:
|
|
60
60
|
run: npm install
|
61
61
|
|
62
62
|
- name: Tests
|
63
|
+
env:
|
64
|
+
TESTOPTS: --verbose
|
63
65
|
run: bundle exec rake
|
64
66
|
timeout-minutes: 3
|
65
67
|
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,42 @@
|
|
1
|
+
22-02-2022
|
2
|
+
|
3
|
+
- Version 4.2.0
|
4
|
+
|
5
|
+
- FEATURE: Add support for `clear_every` parameter in Redis backend
|
6
|
+
|
7
|
+
This allows the clearing of the backlog to take place once every N messages. In high-load scenarios, this can provide significant performance benefit.
|
8
|
+
|
9
|
+
16-02-2022
|
10
|
+
|
11
|
+
- Version 4.1.0
|
12
|
+
|
13
|
+
- PERF: Optimize Client#backlog for up-to-date clients
|
14
|
+
|
15
|
+
Also introduces a new MessageBus#last_ids(*channels) api for fetching the last_ids of
|
16
|
+
multiple channels simultaneously
|
17
|
+
|
18
|
+
11-01-2022
|
19
|
+
|
20
|
+
- Version 4.0.0
|
21
|
+
|
22
|
+
- DEV: Remove backend diagnostics
|
23
|
+
- DEV: Rename reliable_pub_sub to backend_instance
|
24
|
+
- FIX: `destroy` following `after_fork` could thread lock
|
25
|
+
|
26
|
+
31-12-2021
|
27
|
+
|
28
|
+
- Version 3.4.0
|
29
|
+
|
30
|
+
- FEATURE: Remove process auto-termination on missed keepalives
|
31
|
+
|
32
|
+
20-12-2021
|
33
|
+
|
34
|
+
- Version 3.3.8
|
35
|
+
|
36
|
+
- FIX: Restore dist js files to fix a regression in 3.3.7
|
37
|
+
- FIX: Stop various thread/pg connection leaks
|
38
|
+
- DEV: Fix ruby warnings
|
39
|
+
|
1
40
|
15-12-2021
|
2
41
|
|
3
42
|
- Version 3.3.7
|
@@ -63,14 +102,14 @@
|
|
63
102
|
|
64
103
|
- Version 3.3.0
|
65
104
|
|
66
|
-
|
105
|
+
- FEATURE: `MessageBus.base_route=` to alter the route that message bus will listen on.
|
67
106
|
|
68
107
|
07-05-2020
|
69
108
|
|
70
109
|
- Version 3.2.0
|
71
110
|
|
72
|
-
|
73
|
-
|
111
|
+
- FIX: compatibility with Rails 6.0.3, note: apps without ActionDispatch::Flash may stop working after this upgrade
|
112
|
+
to correct this disable middleware injection with `config.skip_message_bus_middleware = true` and configure middleware by hand with `app.middleware.use(MessageBus::Rack::Middleware)`
|
74
113
|
|
75
114
|
28-04-2020
|
76
115
|
|
@@ -105,7 +144,6 @@
|
|
105
144
|
|
106
145
|
- FIX: In the redis backend make the `is_readonly?` method compatible with the redis gem both pre and post v4.0 when the `client` attribute was removed
|
107
146
|
|
108
|
-
|
109
147
|
30-04-2019
|
110
148
|
|
111
149
|
- Version 2.2.1
|
@@ -136,7 +174,7 @@
|
|
136
174
|
- Version 2.2.0.pre
|
137
175
|
|
138
176
|
- FIX: In redis backend we now expire the key used to track channel id this can cause a redis key leak
|
139
|
-
|
177
|
+
with large amounts of subscriptions that go away
|
140
178
|
- FEATURE: Much extra implementation documentation, and some improvements to usage documentation.
|
141
179
|
- FEATURE: Improvements to development workflow:
|
142
180
|
- Fully docker-based development and testing, with no other dependencies.
|
@@ -153,44 +191,47 @@
|
|
153
191
|
- Supports setting backlog size on publication for memory/postgres
|
154
192
|
- FEATURE: `MessageBus.off` now prevents the server subscription from starting up.
|
155
193
|
- FEATURE: Trims unused parts of the public API:
|
194
|
+
|
156
195
|
- Methods removed:
|
157
|
-
|
158
|
-
|
196
|
+
|
197
|
+
- ConnectionManager#stats (never used and the ConnectionManager is not exposed to application code)
|
198
|
+
- Client#cancel (effectively duplicate of Client#close and the Client is only available via the ConnectionManager, thus not available to application code)
|
159
199
|
|
160
200
|
- Methods made private:
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
201
|
+
|
202
|
+
- MessageBus::Implementation#encode_channel_name
|
203
|
+
- MessageBus::Implementation#decode_channel_name
|
204
|
+
- Client#in_async?
|
205
|
+
- Client#ensure_closed!
|
206
|
+
- ConnectionManager#subscribe_client
|
207
|
+
- Diagnostics.full_process_path
|
208
|
+
- Diagnostics.hostname
|
209
|
+
- MessageBus::Rack::Diagnostics#js_asset
|
210
|
+
- MessageBus::Rack::Diagnostics#generate_script_tag
|
211
|
+
- MessageBus::Rack::Diagnostics#file_hash
|
212
|
+
- MessageBus::Rack::Diagnostics#asset_contents
|
213
|
+
- MessageBus::Rack::Diagnostics#asset_path
|
214
|
+
- MessageBus::Rack::Diagnostics#index
|
215
|
+
- MessageBus::Rack::Diagnostics#translate_handlebars
|
216
|
+
- MessageBus::Rack::Diagnostics#indent
|
217
|
+
- MessageBus::Rack::Middleware#start_listener
|
218
|
+
- MessageBus::Rack::Middleware#close_db_connection!
|
219
|
+
- MessageBus::Rack::Middleware#add_client_with_timeout
|
179
220
|
|
180
221
|
- Methods switched from protected to private:
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
222
|
+
- MessageBus::Implementation#global?
|
223
|
+
- MessageBus::Implementation#decode_message!
|
224
|
+
- MessageBus::Implementation#replay_backlog
|
225
|
+
- MessageBus::Implementation#subscribe_impl
|
226
|
+
- MessageBus::Implementation#unsubscribe_impl
|
227
|
+
- MessageBus::Implementation#ensure_subscriber_thread
|
228
|
+
- MessageBus::Implementation#new_subscriber_thread
|
229
|
+
- MessageBus::Implementation#global_subscribe_thread
|
230
|
+
- MessageBus::Implementation#multi_each
|
231
|
+
- Client#write_headers
|
232
|
+
- Client#write_chunk
|
233
|
+
- Client#write_and_close
|
234
|
+
- Client#messages_to_json
|
194
235
|
|
195
236
|
15-10-2018
|
196
237
|
|
@@ -219,7 +260,7 @@
|
|
219
260
|
- Version 2.1.2
|
220
261
|
|
221
262
|
- FEATURE: minHiddenPollInterval set to 1500ms out of the box, ensures we never do hidden tab
|
222
|
-
|
263
|
+
polls at a high rate if tons of tabs are open
|
223
264
|
- FEATURE: added random 500ms to delayed polls to increase tab entropy
|
224
265
|
|
225
266
|
18-12-2017
|
@@ -233,7 +274,7 @@
|
|
233
274
|
- Version 2.1.0
|
234
275
|
|
235
276
|
- FEATURE: you can now lookup last N messages on channel on subscribe from JavaScript
|
236
|
-
|
277
|
+
Subscribe at position (-1 - numberOfMessages) from the client
|
237
278
|
|
238
279
|
24-11-2017
|
239
280
|
|
@@ -253,8 +294,7 @@
|
|
253
294
|
- Version 2.0.7
|
254
295
|
|
255
296
|
- Fix/Feature: use LUA script for publishing to bus, this eliminates a race condition
|
256
|
-
|
257
|
-
|
297
|
+
and ensures that we are never stuck in a multi transaction by mistake
|
258
298
|
|
259
299
|
29-09-2017
|
260
300
|
|
@@ -282,12 +322,10 @@
|
|
282
322
|
- Version 2.0.2
|
283
323
|
- Feature: Add on_middleware_error callback for remapping middleware errors to HTTP results
|
284
324
|
|
285
|
-
|
286
325
|
25-07-2016
|
287
326
|
|
288
327
|
- Feature: Add JavaScript MessageBus.status() function
|
289
328
|
|
290
|
-
|
291
329
|
21-06-2016
|
292
330
|
|
293
331
|
- Version 2.0.1
|
@@ -368,8 +406,8 @@
|
|
368
406
|
|
369
407
|
- Version 1.1.1
|
370
408
|
- Fix: In multisite config there was no way to specify site for last_id or backlog
|
371
|
-
|
372
|
-
|
409
|
+
to resolve overrides were added to #last_id and #backlog, MessageBus::Client now
|
410
|
+
uses the new overrides
|
373
411
|
|
374
412
|
07-12-2015
|
375
413
|
|
@@ -379,86 +417,105 @@
|
|
379
417
|
- Feature: remove most jQuery dependency from message-bus.js
|
380
418
|
|
381
419
|
09-07-2015
|
420
|
+
|
382
421
|
- Version 1.0.16
|
383
422
|
- Fix: correct edge cases around keepalive checks on bus
|
384
423
|
|
385
424
|
09-07-2015
|
425
|
+
|
386
426
|
- Version 1.0.15
|
387
427
|
- Feature: MessageBus.reliable_pub_sub.max_backlog_age (in secs) configurable (default to 7 days)
|
388
428
|
- Fix: API for MessageBus.backlog("/bla") was returning global backlog by mistake
|
389
429
|
- Change: Max global backlog size reduced to 2000 elements
|
390
430
|
|
391
431
|
08-06-2015
|
432
|
+
|
392
433
|
- Version 1.0.14
|
393
434
|
- Fix: we can not use Thread#kill best keepalive can do is terminate process cleanly
|
394
435
|
- Feature: you can opt-out of keepalive with MessageBus.keepalive_timeout = 0
|
395
436
|
|
396
437
|
08-06-2015
|
438
|
+
|
397
439
|
- Version 1.0.13
|
398
440
|
- Fix: on global subscribe reconnect replay missed messages
|
399
441
|
- Feature: keepalive tests for global subscribe, catches hung redis connections
|
400
442
|
|
401
443
|
28-05-2015
|
444
|
+
|
402
445
|
- Version 1.0.12
|
403
446
|
- Feature: Support client_id targeted message
|
404
447
|
|
405
448
|
06-05-2015
|
449
|
+
|
406
450
|
- Version 1.0.11
|
407
451
|
- Fix: race condition in TimerThread
|
408
452
|
|
409
453
|
01-05-2015
|
454
|
+
|
410
455
|
- Version: 1.0.10
|
411
456
|
- Feature: no longer depends on EventMachine (only used for Thin backend)
|
412
457
|
- Feature: reliable pub sub will queue messages in memory if redis is readonly, configurable
|
413
458
|
- Fix: if redis is flushed we will continue to deliver messages
|
414
459
|
|
415
460
|
23-03-2015
|
461
|
+
|
416
462
|
- Version 1.0.9
|
417
463
|
- Fix: inherit off StandardError not Exception for all exceptions raised
|
418
464
|
|
419
465
|
20-03-2015
|
466
|
+
|
420
467
|
- Version 1.0.8
|
421
468
|
- Fix: aggressive short polling in background
|
422
469
|
|
423
470
|
16-03-2015
|
471
|
+
|
424
472
|
- Version 1.0.7
|
425
473
|
- Feature: added pause and resume methods
|
426
474
|
|
427
475
|
03-02-2015
|
476
|
+
|
428
477
|
- Version 1.0.6
|
429
478
|
- Fix: global backlog not truncating correctly
|
430
479
|
|
431
480
|
23-09-2014
|
481
|
+
|
432
482
|
- Version 1.0.5
|
433
483
|
- Fix: missing custom headers from long polls
|
434
484
|
|
435
485
|
23-09-2014
|
486
|
+
|
436
487
|
- Version 1.0.4
|
437
488
|
- Change: MessageBus.access_control_allow_origin_lookup to extra_response_headers_lookup
|
438
489
|
|
439
490
|
23-09-2014
|
491
|
+
|
440
492
|
- Version 1.0.3
|
441
493
|
- Change: MessageBus.access_control_allow_origin to MessageBus.access_control_allow_origin_lookup
|
442
494
|
|
443
495
|
23-09-2014
|
496
|
+
|
444
497
|
- Version 1.0.2
|
445
498
|
- Feature: MessageBus.access_control_allow_origin to control origin header
|
446
499
|
|
447
500
|
23-09-2014
|
501
|
+
|
448
502
|
- Version 1.0.1
|
449
503
|
- Feature: $.ajax dependency can be passed in.
|
450
504
|
- Feature: unsubscribe accepts a second param for the function to unsubscribe.
|
451
505
|
|
452
506
|
22-09-2014
|
507
|
+
|
453
508
|
- Version 1.0.0
|
454
509
|
- Feature: add backgroundCallbackInterval - interval to send polls when page is in the background
|
455
510
|
- Feature: issue a long poll as soon as page moves into the foreground
|
456
511
|
|
457
512
|
11-08-2014
|
513
|
+
|
458
514
|
- Version 0.9.5
|
459
515
|
- Fix: release db connection a lot earlier for long polling (rails defer closes)
|
460
516
|
|
461
517
|
13-01-2014
|
518
|
+
|
462
519
|
- Version 0.9.4
|
463
520
|
- Added support for /global/ channel to publish messages across a multisite
|
464
521
|
- Cleaned up test harness so it uses local bus as opposed to global
|
@@ -467,19 +524,23 @@
|
|
467
524
|
- ensure_reactor could say the reactor is running, but it was not, on first call
|
468
525
|
|
469
526
|
06-12-2013
|
527
|
+
|
470
528
|
- Version 0.9.3.2
|
471
529
|
- Fix permissions in gem
|
472
530
|
|
473
531
|
05-12-2013
|
532
|
+
|
474
533
|
- Version 0.9.3.1
|
475
534
|
- Add MessageBus.diagnostics() for diagnosing bus issues client side
|
476
535
|
- Add more robustness to JavaScript, if callbacks used to fail they would halt the chain
|
477
536
|
|
478
537
|
03-12-2013
|
538
|
+
|
479
539
|
- Version 0.9.3
|
480
540
|
- Remove thin dependency
|
481
541
|
- Improve robustness under failure conditions
|
482
542
|
|
483
543
|
30-09-2013
|
544
|
+
|
484
545
|
- Fix failures in Ruby 1.9
|
485
546
|
- Set up rack hijack by default in light of passengers new setting
|
data/README.md
CHANGED
@@ -26,15 +26,21 @@ MessageBus only support officially supported versions of Ruby; as of [2021-03-31
|
|
26
26
|
|
27
27
|
Add this line to your application's Gemfile:
|
28
28
|
|
29
|
-
|
29
|
+
```ruby
|
30
|
+
gem 'message_bus'
|
31
|
+
```
|
30
32
|
|
31
33
|
And then execute:
|
32
34
|
|
33
|
-
|
35
|
+
```shell
|
36
|
+
$ bundle
|
37
|
+
```
|
34
38
|
|
35
39
|
Or install it yourself as:
|
36
40
|
|
37
|
-
|
41
|
+
```shell
|
42
|
+
$ gem install message_bus
|
43
|
+
```
|
38
44
|
|
39
45
|
## Usage
|
40
46
|
|
@@ -109,7 +115,7 @@ MessageBus.user_id_lookup do |env|
|
|
109
115
|
end
|
110
116
|
```
|
111
117
|
|
112
|
-
If both `user_ids` and `group_ids` options are supplied when publishing a message, the message will be targeted at clients with lookup return values that
|
118
|
+
If both `user_ids` and `group_ids` options are supplied when publishing a message, the message will be targeted at clients with lookup return values that matches on either the `user_ids` **or** the `group_ids` options.
|
113
119
|
|
114
120
|
```ruby
|
115
121
|
MessageBus.publish "/channel", "hello", user_ids: [1, 2, 3], group_ids: [1, 2, 3]
|
@@ -129,7 +135,7 @@ Custom client message filters can be registered via `MessageBus#register_client_
|
|
129
135
|
|
130
136
|
For example, ensuring that only messages seen by the server in the last 20 seconds are published to the client:
|
131
137
|
|
132
|
-
```
|
138
|
+
```ruby
|
133
139
|
MessageBus.register_client_message_filter('/test') do |message|
|
134
140
|
(Time.now.to_i - message.data[:published_at]) <= 20
|
135
141
|
end
|
@@ -163,32 +169,6 @@ curl -H "Content-Type: application/x-www-form-urlencoded" -X POST --data "/messa
|
|
163
169
|
|
164
170
|
You should see a reply with the messages of that channel you requested (in this case `/message`) starting at the message ID you requested (`0`). The URL parameter `dlp=t` disables long-polling: we do not want this request to stay open.
|
165
171
|
|
166
|
-
### Diagnostics
|
167
|
-
|
168
|
-
MessageBus comes with a diagnostics interface, which you can access at `/message-bus/_diagnostics`. This interface allows you visibility into the runtime behaviour of message_bus.
|
169
|
-
|
170
|
-
In order to use the diagnostics UI in your application, it is necessary to:
|
171
|
-
|
172
|
-
* Enable it
|
173
|
-
* Define a user ID for requests
|
174
|
-
* Define a check for admin role
|
175
|
-
|
176
|
-
as an example, you can do something like this:
|
177
|
-
|
178
|
-
```ruby
|
179
|
-
MessageBus.enable_diagnostics # Must be called after `MessageBus.after_fork` if using a forking webserver
|
180
|
-
|
181
|
-
MessageBus.user_id_lookup do |_env|
|
182
|
-
1
|
183
|
-
end
|
184
|
-
|
185
|
-
MessageBus.is_admin_lookup do |_env|
|
186
|
-
true
|
187
|
-
end
|
188
|
-
```
|
189
|
-
|
190
|
-
Of course, in your real-world application, you would define these values according to your authentication/authorization logic.
|
191
|
-
|
192
172
|
### Transport
|
193
173
|
|
194
174
|
MessageBus ships with 3 transport mechanisms.
|
@@ -280,7 +260,7 @@ MessageBus.start(); // call once at startup
|
|
280
260
|
MessageBus.callbackInterval = 500;
|
281
261
|
|
282
262
|
// you will get all new messages sent to channel
|
283
|
-
MessageBus.subscribe("/channel", function(data){
|
263
|
+
MessageBus.subscribe("/channel", function (data) {
|
284
264
|
// data shipped from server
|
285
265
|
});
|
286
266
|
|
@@ -386,6 +366,16 @@ headers|{}|Extra headers to be include with requests. Properties and values of o
|
|
386
366
|
|
387
367
|
message_bus can be configured to use one of several available storage backends, and each has its own configuration options.
|
388
368
|
|
369
|
+
### Keepalive
|
370
|
+
|
371
|
+
To ensure correct operation of message_bus, every 60 seconds a message is broadcast to itself. If for any reason the message is not consumed by the same process within 3 keepalive intervals a warning log message is raised.
|
372
|
+
|
373
|
+
To control keepalive interval use
|
374
|
+
|
375
|
+
```ruby
|
376
|
+
MessageBus.configure(keepalive_interval: 60)
|
377
|
+
```
|
378
|
+
|
389
379
|
### Redis
|
390
380
|
|
391
381
|
message_bus supports using Redis as a storage backend, and you can configure message_bus to use redis in `config/initializers/message_bus.rb`, like so:
|
@@ -398,19 +388,24 @@ The redis client message_bus uses is [redis-rb](https://github.com/redis/redis-r
|
|
398
388
|
|
399
389
|
#### Data Retention
|
400
390
|
|
401
|
-
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
|
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.
|
402
394
|
|
403
|
-
This is configurable via accessors on the
|
395
|
+
This is configurable via accessors on the Backend instance.
|
404
396
|
|
405
397
|
```ruby
|
406
398
|
# only store 100 messages per channel
|
407
|
-
MessageBus.
|
399
|
+
MessageBus.backend_instance.max_backlog_size = 100
|
408
400
|
|
409
401
|
# only store 100 global messages
|
410
|
-
MessageBus.
|
402
|
+
MessageBus.backend_instance.max_global_backlog_size = 100
|
411
403
|
|
412
404
|
# flush per-channel backlog after 100 seconds of inactivity
|
413
|
-
MessageBus.
|
405
|
+
MessageBus.backend_instance.max_backlog_age = 100
|
406
|
+
|
407
|
+
# clear the backlog every 50 messages
|
408
|
+
MessageBus.backend_instance.clear_every = 50
|
414
409
|
```
|
415
410
|
|
416
411
|
### PostgreSQL
|
@@ -433,8 +428,7 @@ message_bus also supports an in-memory backend. This can be used for testing or
|
|
433
428
|
MessageBus.configure(backend: :memory)
|
434
429
|
```
|
435
430
|
|
436
|
-
The `:clear_every` option supported
|
437
|
-
|
431
|
+
The `:clear_every` option is supported in the same way as the PostgreSQL backend.
|
438
432
|
|
439
433
|
### Transport codecs
|
440
434
|
|
@@ -456,7 +450,7 @@ Keep in mind, much of MessageBus internals and supporting tools expect data to b
|
|
456
450
|
|
457
451
|
Another example may be very large and complicated messages where Oj in compatibility mode outperforms JSON. To opt for the Oj codec use:
|
458
452
|
|
459
|
-
```
|
453
|
+
```ruby
|
460
454
|
MessageBus.configure(transport_codec: MessageBus::Codec::Oj.new)
|
461
455
|
```
|
462
456
|
|
@@ -503,7 +497,6 @@ For more information see the [Passenger documentation](https://www.phusionpassen
|
|
503
497
|
|
504
498
|
```ruby
|
505
499
|
# path/to/your/config/puma.rb
|
506
|
-
require 'message_bus' # omit this line for Rails 5
|
507
500
|
on_worker_boot do
|
508
501
|
MessageBus.after_fork
|
509
502
|
end
|
@@ -513,7 +506,6 @@ end
|
|
513
506
|
|
514
507
|
```ruby
|
515
508
|
# path/to/your/config/unicorn.rb
|
516
|
-
require 'message_bus'
|
517
509
|
after_fork do |server, worker|
|
518
510
|
MessageBus.after_fork
|
519
511
|
end
|
@@ -554,26 +546,21 @@ MessageBus ships with an optional `DistributedCache` API which provides a simple
|
|
554
546
|
require 'message_bus/distributed_cache'
|
555
547
|
|
556
548
|
# process 1
|
557
|
-
|
558
549
|
cache = MessageBus::DistributedCache.new("animals")
|
559
550
|
|
560
551
|
# process 2
|
561
|
-
|
562
552
|
cache = MessageBus::DistributedCache.new("animals")
|
563
553
|
|
564
554
|
# process 1
|
565
|
-
|
566
555
|
cache["frogs"] = 5
|
567
556
|
|
568
557
|
# process 2
|
569
|
-
|
570
558
|
puts cache["frogs"]
|
571
559
|
# => 5
|
572
560
|
|
573
561
|
cache["frogs"] = nil
|
574
562
|
|
575
563
|
# process 1
|
576
|
-
|
577
564
|
puts cache["frogs"]
|
578
565
|
# => nil
|
579
566
|
```
|
@@ -631,7 +618,7 @@ In e.g. `config/initializers/message_bus.rb`:
|
|
631
618
|
```ruby
|
632
619
|
MessageBus.extra_response_headers_lookup do |env|
|
633
620
|
[
|
634
|
-
|
621
|
+
["Access-Control-Allow-Origin", "http://example.com:3000"],
|
635
622
|
]
|
636
623
|
end
|
637
624
|
```
|
@@ -692,8 +679,8 @@ In certain conditions, a status message will be delivered and look like this:
|
|
692
679
|
"message_id": -1,
|
693
680
|
"channel": "/__status",
|
694
681
|
"data": {
|
695
|
-
"/some/channel":5,
|
696
|
-
"/other/channel":9
|
682
|
+
"/some/channel": 5,
|
683
|
+
"/other/channel": 9
|
697
684
|
}
|
698
685
|
}
|
699
686
|
```
|
@@ -727,7 +714,7 @@ When submitting a PR, please be sure to include notes on it in the `Unreleased`
|
|
727
714
|
|
728
715
|
To run tests you need both Postgres and Redis installed. By default on Redis the tests connect to `localhost:6379` and on Postgres connect the database `localhost:5432/message_bus_test` with the system username; if you wish to override this, you can set alternative values:
|
729
716
|
|
730
|
-
```
|
717
|
+
```shell
|
731
718
|
PGUSER=some_user PGDATABASE=some_db bundle exec rake
|
732
719
|
```
|
733
720
|
|
@@ -742,7 +729,3 @@ While working on documentation, it is useful to automatically re-build it as you
|
|
742
729
|
### Benchmarks
|
743
730
|
|
744
731
|
Some simple benchmarks are implemented in `spec/performance` and can be executed using `rake performance` (or `docker-compose run tests rake performance`). You should run these before and after your changes to avoid introducing performance regressions.
|
745
|
-
|
746
|
-
### Diagnostics Interface
|
747
|
-
|
748
|
-
It is possible to manually test the diagnostics interface by executing `docker-compose up example` and then `open http://localhost:9292`.
|