New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

message-bus-client

Package Overview
Dependencies
Maintainers
6
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

message-bus-client - npm Package Compare versions

Comparing version 3.3.7 to 4.0.0

16

package.json
{
"name": "message-bus-client",
"version": "3.3.7",
"version": "4.0.0",
"description": "A message bus client in Javascript",
"main": "assets/message-bus.js",
"keywords": "es6, modules",
"keywords": [
"es6",
"modules"
],
"files": [

@@ -12,6 +15,3 @@ "assets/message-bus.js"

"module": "assets/message-bus.js",
"repository": {
"type": "git",
"url": "git+https://github.com/discourse/message_bus.git"
},
"repository": "https://github.com/discourse/message_bus",
"author": "Sam Saffron, Robin Ward",

@@ -24,4 +24,6 @@ "license": "MIT",

"devDependencies": {
"eslint": "^7.27.0"
"eslint": "^7.27.0",
"jasmine-browser-runner": "^0.10.0",
"jasmine-core": "^3.10.1"
}
}

@@ -15,3 +15,3 @@ # MessageBus

MessageBus only support officially supported versions of Ruby; as of [2018-06-20](https://www.ruby-lang.org/en/news/2018/06/20/support-of-ruby-2-2-has-ended/) this means we only support Ruby version 2.3 and up.
MessageBus only support officially supported versions of Ruby; as of [2021-03-31](https://www.ruby-lang.org/en/downloads/branches/) this means we only support Ruby version 2.6 and up.

@@ -30,11 +30,17 @@ ## Can you handle concurrent requests?

gem 'message_bus'
```ruby
gem 'message_bus'
```
And then execute:
$ bundle
```shell
$ bundle
```
Or install it yourself as:
$ gem install message_bus
```shell
$ gem install message_bus
```

@@ -73,5 +79,5 @@ ## Usage

### Targetted messages
### Targeted messages
Messages can be targetted to particular clients by supplying the `client_ids` option when publishing a message.
Messages can be targeted to particular clients by supplying the `client_ids` option when publishing a message.

@@ -82,7 +88,7 @@ ```ruby

By configuring the `user_id_lookup` and `group_ids_lookup` options with a Proc or Lambda which will be called with a [Rack specification environment](https://github.com/rack/rack/blob/master/SPEC.rdoc#the-environment-), messages can be targetted to particular clients users or groups by supplying either the `user_ids` or `group_ids` options when publishing a message.
By configuring the `user_id_lookup` and `group_ids_lookup` options with a Proc or Lambda which will be called with a [Rack specification environment](https://github.com/rack/rack/blob/master/SPEC.rdoc#the-environment-), messages can be targeted to particular clients users or groups by supplying either the `user_ids` or `group_ids` options when publishing a message.
```ruby
MessageBus.configure(user_id_lookup: proc do |env|
# this lookup occurs on JS-client poolings, so that server can retrieve backlog
# this lookup occurs on JS-client polling, so that server can retrieve backlog
# for the client considering/matching/filtering user_ids set on published messages

@@ -105,3 +111,3 @@ # if user_id is not set on publish time, any user_id returned here will receive the message

# example of MessageBus to set user_ids from an initializer in Rails and Devise:
# config/inializers/message_bus.rb
# config/initializers/message_bus.rb
MessageBus.user_id_lookup do |env|

@@ -117,3 +123,3 @@ req = Rack::Request.new(env)

If both `user_ids` and `group_ids` options are supplied when publishing a message, the message will be targetted at clients with lookup return values that matches on either the `user_ids` **or** the `group_ids` options.
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.

@@ -124,3 +130,3 @@ ```ruby

If the `client_ids` option is supplied with either the `user_ids` or `group_ids` options when publising a message, the `client_ids` option will be applied unconditionally and messages will be filtered further using `user_id` or `group_id` clauses.
If the `client_ids` option is supplied with either the `user_ids` or `group_ids` options when publishing a message, the `client_ids` option will be applied unconditionally and messages will be filtered further using `user_id` or `group_id` clauses.

@@ -139,3 +145,3 @@ ```ruby

```
```ruby
MessageBus.register_client_message_filter('/test') do |message|

@@ -174,28 +180,2 @@ (Time.now.to_i - message.data[:published_at]) <= 20

### Diagnostics
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.
In order to use the diagnostics UI in your application, it is necessary to:
* Enable it
* Define a user ID for requests
* Define a check for admin role
as an example, you can do something like this:
```ruby
MessageBus.enable_diagnostics # Must be called after `MessageBus.after_fork` if using a forking webserver
MessageBus.user_id_lookup do |_env|
1
end
MessageBus.is_admin_lookup do |_env|
true
end
```
Of course, in your real-world application, you would define these values according to your authentication/authorization logic.
### Transport

@@ -257,3 +237,3 @@

# you can also choose to pass the `:site_id`.
# This takes precendence over whatever `site_id_lookup`
# This takes precedence over whatever `site_id_lookup`
# returns

@@ -293,3 +273,3 @@ MessageBus.publish "/channel", "some message", site_id: "site-id"

// you will get all new messages sent to channel
MessageBus.subscribe("/channel", function(data){
MessageBus.subscribe("/channel", function (data) {
// data shipped from server

@@ -400,2 +380,12 @@ });

### Keepalive
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.
To control keepalive interval use
```ruby
MessageBus.configure(keepalive_interval: 60)
```
### Redis

@@ -415,13 +405,13 @@

This is configurable via accessors on the ReliablePubSub instance.
This is configurable via accessors on the Backend instance.
```ruby
# only store 100 messages per channel
MessageBus.reliable_pub_sub.max_backlog_size = 100
MessageBus.backend_instance.max_backlog_size = 100
# only store 100 global messages
MessageBus.reliable_pub_sub.max_global_backlog_size = 100
MessageBus.backend_instance.max_global_backlog_size = 100
# flush per-channel backlog after 100 seconds of inactivity
MessageBus.reliable_pub_sub.max_backlog_age = 100
MessageBus.backend_instance.max_backlog_age = 100
```

@@ -451,3 +441,2 @@

### Transport codecs

@@ -471,5 +460,5 @@

Another example may be very large and complicated messages where Oj in compatability mode outperforms JSON. To opt for the Oj codec use:
Another example may be very large and complicated messages where Oj in compatibility mode outperforms JSON. To opt for the Oj codec use:
```
```ruby
MessageBus.configure(transport_codec: MessageBus::Codec::Oj.new)

@@ -521,3 +510,2 @@ ```

# path/to/your/config/puma.rb
require 'message_bus' # omit this line for Rails 5
on_worker_boot do

@@ -532,3 +520,2 @@ MessageBus.after_fork

# path/to/your/config/unicorn.rb
require 'message_bus'
after_fork do |server, worker|

@@ -574,15 +561,11 @@ MessageBus.after_fork

# process 1
cache = MessageBus::DistributedCache.new("animals")
# process 2
cache = MessageBus::DistributedCache.new("animals")
# process 1
cache["frogs"] = 5
# process 2
puts cache["frogs"]

@@ -594,3 +577,2 @@ # => 5

# process 1
puts cache["frogs"]

@@ -653,3 +635,3 @@ # => nil

[
["Access-Control-Allow-Origin", "http://example.com:3000"],
["Access-Control-Allow-Origin", "http://example.com:3000"],
]

@@ -715,4 +697,4 @@ end

"data": {
"/some/channel":5,
"/other/channel":9
"/some/channel": 5,
"/other/channel": 9
}

@@ -751,3 +733,3 @@ }

```
```shell
PGUSER=some_user PGDATABASE=some_db bundle exec rake

@@ -767,5 +749,1 @@ ```

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.
### Diagnostics Interface
It is possible to manually test the diagnostics interface by executing `docker-compose up example` and then `open http://localhost:9292`.

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc