anycable 0.6.3 → 1.0.0.rc1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 982192dbe84e0576b13033aadf3ead0238e28bf4c30b6dec2d08228cd2093f3c
4
- data.tar.gz: 9af924544238340e0c5b171a738b9bec99ebe25c13cc398d279318f6c9cbef12
3
+ metadata.gz: deebe94f2e541a9d14ccf4a56df910cdb5a2fb17ae6815ffaaa2f761fdcd07ad
4
+ data.tar.gz: e96c5b0d28dd7617c2cfa1249fde5bd357465be7596915720c27718f486c4f16
5
5
  SHA512:
6
- metadata.gz: ba03a684ddce90df929c469deb4b219a494578ab9c203321e9c9f900810f98132eb74d8fc16aa1b79c6042c28bd5b3da2ac83d39bd4e25944127191dc4b2f8b7
7
- data.tar.gz: 77a874ad448dff0cca9d8ada4259c8c48ab4fdb87d1df1f3c6bee1dab50f23335f1fc390ee60fb96483a89cc0071700945bdffa73f908745987de2c2e7877c91
6
+ metadata.gz: b585f2797184d7bc78cc761707b741dcfa8a6b796df91cccd7ac1e44c9210a84852daba838adaaa6b2f1548d2d0f82cf57713b32a4a86d0ffa671f64321b9df1
7
+ data.tar.gz: dccd27127eaafc5b7821ba18404546269e9aaf3163faccffaba864e166cb1c19cdc914ccf9de87da963cac447541058e0d7ba906674298f9dda8573ca4e917c8
@@ -1,246 +1,47 @@
1
1
  # Change log
2
2
 
3
- ## master
3
+ ## 1.0.0.rc1 (2020-06-10)
4
4
 
5
- ## 0.6.3 (2019-03-26)
5
+ - Add `Env#istate` and `EnvResponse#istate` to store channel state. ([@palkan][])
6
6
 
7
- - Relax `redis` gem version requirement. ([@palkan][])
7
+ That would allow to mimic instance variables usage in Action Cable channels.
8
8
 
9
- Use the same restriction as Action Cable does (`>= 3`).
9
+ - Add `CommandResponse#stopped_streams` to support unsubscribing from particular broadcastings. ([@palkan])
10
10
 
11
- ## 0.6.2 (2019-03-15)
11
+ `Socket#unsubscribe` is now implemented as well.
12
12
 
13
- - Add GRPC service method name and message content to exception notifications ([@sponomarev][])
13
+ - Add `AnyCable.broadcast_adapter#broadcast_command` method. ([@palkan][])
14
14
 
15
- `Anycable.capture_exception` allows accessing GRPC service method name and message content
16
- on which an exception was captured. It can be used for exceptions grouping in your tracker and
17
- providing additional data to investigate a root of a problem.
15
+ It could be used to send commands to WS server (e.g., remote disconnect).
18
16
 
19
- Example:
17
+ - Add `:http` broadcasting adapter. ([@palkan][])
20
18
 
21
- ```ruby
22
- AnyCable.capture_exception do |ex, method, message|
23
- Honeybadger.notify(ex, component: "any_cable", action: method, params: message)
24
- end
25
- ```
19
+ - **RPC schema has changed**. ([@palkan][])
26
20
 
27
- Usage of a handler proc with just a single argument is preserved for the sake of compatibility.
21
+ Using `anycable-go` v1.x is required.
28
22
 
29
- - Add deprecation warning to default host usage ([@sponomarev][])
23
+ - **Ruby 2.5+ is required**. ([@palkan][])
30
24
 
31
- Exposing AnyCable publicly is considered to be harmful and planned to be changed
32
- in future versions.
25
+ - Added RPC proto version check. ([@palkan][])
33
26
 
34
- - Allow running the server as a detachable daemon ([@sponomarev][])
27
+ Server must sent `protov` metadata with the supported versions (comma-separated list). If there is no matching version an exception is raised.
35
28
 
36
- Server is fully managed by the binary itself.
29
+ Current RPC proto version is **v1**.
37
30
 
38
- ```
39
- # Start anycable daemon
40
- $ bundle exec anycabled start
31
+ - Added `request` support to channels. ([@palkan][])
41
32
 
42
- # Pass cli options to anycable through daemon. Separate daemon options and anycable options with `--`
43
- $ bundle exec anycabled start -- --rpc-host 127.0.0.1:31337
33
+ Now you can access `request` object in channels, too (e.g., to read headers/cookies/URL/etc).
44
34
 
45
- # Stop anycable daemon
46
- $ bundle exec anycabled stop
35
+ - Change default server address from `[::]:50051` to `127.0.0.1:50051`. ([@palkan][])
47
36
 
48
- # See more anycable daemon options
49
- $ bundle exec anycabled
50
- ```
37
+ See [#71](https://github.com/anycable/anycable/pull/71).
51
38
 
52
- ## 0.6.1 (2019-01-05)
39
+ - Fix building Redis Sentinel config. ([@palkan][])
53
40
 
54
- - [Fix #63](https://github.com/anycable/anycable-rails/issues/63) Load `anyway_config` after application boot to make sure that all frameworks dependent functionality is loaded. ([@palkan][])
41
+ ---
55
42
 
56
- ## 0.6.0 (2018-11-15)
57
-
58
- ### Features
59
-
60
- #### Broadcast adapters
61
-
62
- AnyCable allows you to use custom broadcasting adapters (Redis is used by default):
63
-
64
- ```ruby
65
- # Specify by name (tries to load `AnyCable::BroadcastAdapters::MyAdapter` from
66
- # "anycable/broadcast_adapters/my_adapter")
67
- AnyCable.broadcast_adapter = :my_adapter, { option: "value" }
68
- # or provide an instance (should respond_to #broadcast)
69
- AnyCable.broadcast_adapter = MyAdapter.new
70
- ```
71
-
72
- **Breaking:** to use Redis adapter you must ensure that it is present in your Gemfile; AnyCable gem doesn't have `redis` as a dependency anymore.
73
-
74
- #### CLI
75
-
76
- AnyCable now ships with a CLI–`anycable`.
77
-
78
- Use it to run a gRPC server:
79
-
80
- ```sh
81
- # run anycable and load app from app.rb
82
- bundle exec anycable -r app.rb
83
- # or
84
- bundle exec anycable --require app.rb
85
- ```
86
-
87
- All configuration options are also supported as CLI options (see `anycable -h` for more information).
88
-
89
- The only required options is the application file to load (`-r/--require`).
90
-
91
- You can omit it if you want to load an app form `./config/environment.rb` (e.g. with Rails) or `./config/anycable.rb`.
92
-
93
- AnyCable CLI also allows you to run a separate command (process) from within a RPC server:
94
-
95
- ```sh
96
- $ bundle exec anycable --server-command "anycable-go -p 3334"
97
- ```
98
-
99
- #### Configuration
100
-
101
- - Default server host is changed from `localhost:50051` to `0.0.0.0:50051`
102
- - Expose gRPC server parameters via `rpc_*` config params:
103
-
104
- ```ruby
105
- AnyCable.configure do |config|
106
- config.rpc_pool_size = 120
107
- config.rpc_max_waiting_requests = 10
108
- # etc
109
- end
110
- ```
111
- - `REDIS_URL` env is used by default if present (and no `ANYCABLE_REDIS_URL` specified)
112
- - Make HTTP health check url configurable
113
- - Add ability to pass Redis Sentinel config as array of string.
114
-
115
- Now it's possible to pass Sentinel configuration via env vars:
116
-
117
- ```sh
118
- ANYCABLE_REDIS_SENTINELS=127.0.0.1:26380,127.0.0.1:26381 bundle exec anycable
119
- ```
120
-
121
- #### Other
122
-
123
- - Added middlewares support
124
-
125
- See [docs](https://docs.anycable.io/#/./middlewares).
126
-
127
- - Added gRPC health checker.
128
-
129
- See [docs](https://docs.anycable.io/#/./health_checking).
130
-
131
- - Added hook to run code only within RPC server context.
132
-
133
- Use `AnyCable.configure_server { ... }` to run code only when RPC server is running.
134
-
135
- ### API changes
136
-
137
- **NOTE**: the old API is still working but deprecated (you'll see a notice).
138
-
139
- - Use `AnyCable` instead of `Anycable`
140
-
141
- - New API for registering error handlers:
142
-
143
- ```ruby
144
- AnyCable.capture_exception do |ex|
145
- Honeybadger.notify(ex)
146
- end
147
- ```
148
-
149
- - `AnyCable::Server.start` is deprecated
150
-
151
-
152
- ## 0.5.2 (2018-09-06)
153
-
154
- - [#48](https://github.com/anycable/anycable/pull/48) Add HTTP health server ([@DarthSim][])
155
-
156
- ## 0.5.1 (2018-06-13)
157
-
158
- Minor fixes.
159
-
160
- ## 0.5.0 (2017-10-21)
161
-
162
- - [#2](https://github.com/anycable/anycable/issues/2) Add support for [Redis Sentinel](https://redis.io/topics/sentinel). ([@accessd][])
163
-
164
- - [#28](https://github.com/anycable/anycable/issues/28) Support arbitrary headers. ([@palkan][])
165
-
166
- Previously we hardcoded only "Cookie" header. Now we add all passed headers by WebSocket server to request env.
167
-
168
- - [#27](https://github.com/anycable/anycable/issues/27) Add `error_msg` to RPC responses. ([@palkan][])
169
-
170
- Now RPC responses has 3 statuses:
171
-
172
- - `SUCCESS` – successful request, operation succeed
173
- - `FAILURE` – successful request, operation failed (e.g. authentication failed)
174
- - `ERROR` – request failed (exception raised).
175
-
176
- We provide `error_msg` only when request status is `ERROR`.
177
-
178
- - [#25](https://github.com/anycable/anycable/issues/25) Improve logging and exceptions handling. ([@palkan][])
179
-
180
- Default logger logs to STDOUT with `info` level by default but can be configured to log to file with
181
- any severity.
182
-
183
- GRPC logging is turned off by default (can be turned on through `log_grpc` configuration parameter).
184
-
185
- `ANYCABLE_DEBUG=1` acts as a shortcut to set `debug` level and turn on GRPC logging.
186
-
187
- Now it's possible to add custom exception handlers (e.g. to notify external exception tracking services).
188
-
189
- More on [Wiki](https://github.com/anycable/anycable/wiki/Logging-&-Exceptions-Handling).
190
-
191
- ## 0.4.6 (2017-05-20)
192
-
193
- - Add `Anycable::Server#stop` method. ([@sadovnik][])
194
-
195
- ## 0.4.5 (2017-03-17)
196
-
197
- - Fixed #11. ([@palkan][])
198
-
199
- ## 0.4.4 (2017-03-06)
200
-
201
- - Handle `StandardError` gracefully in RPC calls. ([@palkan][])
202
-
203
- ## 0.4.3 (2017-02-18)
204
-
205
- - Update `grpc` version dependency to support Ruby 2.4. ([@palkan][])
206
-
207
- ## 0.4.2 (2017-01-28)
208
-
209
- - Change socket streaming API. ([@palkan][])
210
-
211
- Add `Socket#subscribe`, `unsubscribe` and `unsubscribe_from_all` methods.
212
-
213
- ## 0.4.1 (2017-01-24)
214
-
215
- - Introduce _fake_ socket instance to handle transmissions and streams. ([@palkan][])
216
-
217
- - Make commands handling more abstract. ([@palkan][])
218
-
219
- We now do not explicitly call channels action but use the only one entrypoing for all commands:
220
-
221
- ```ruby
222
- connection.handle_channel_command(identifier, command, data)
223
- ```
224
-
225
- This method should return `true` if command was successful and `false` otherwise.
226
-
227
- ## 0.4.0 (2017-01-22)
228
-
229
- - Refactor RPC API. ([@palkan][])
230
-
231
- Replace `Subscribe`, `Unsubscribe` and `Perform` methods with `Command` method.
232
-
233
- - Extract Rails functionality to separate gem. ([@palkan][])
234
-
235
- All Rails specifics now live here https://github.com/anycable/anycable-rails.
236
-
237
- ## 0.3.0 (2016-12-28)
238
-
239
- - Handle `Disconnect` requests. ([@palkan][])
240
-
241
- Implement `Disconnect` handler, which invokes `Connection#disconnect` (along with `Channel#unsubscribed` for each subscription).
43
+ See [Changelog](https://github.com/anycable/anycable/blob/0-6-stable/CHANGELOG.md) for versions <1.0.0.
242
44
 
243
45
  [@palkan]: https://github.com/palkan
244
- [@sadovnik]: https://github.com/sadovnik
245
- [@accessd]: https://github.com/accessd
246
- [@DarthSim]: https://github.com/DarthSim
46
+ [@sponomarev]: https://github.com/sponomarev
47
+ [@bibendi]: https://github.com/bibendi
@@ -1,4 +1,4 @@
1
- Copyright 2017-2019 Vladimir Dementyev
1
+ Copyright 2017-2020 Vladimir Dementyev
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,27 +1,31 @@
1
- [![GitPitch](https://gitpitch.com/assets/badge.svg)](https://gitpitch.com/anycable/anycable/master?grs=github) [![Gem Version](https://badge.fury.io/rb/anycable.svg)](https://rubygems.org/gems/anycable) [![Build Status](https://travis-ci.org/anycable/anycable.svg?branch=master)](https://travis-ci.org/anycable/anycable)
1
+ [![GitPitch](https://gitpitch.com/assets/badge.svg)](https://gitpitch.com/anycable/anycable/master?grs=github)
2
+ [![Gem Version](https://badge.fury.io/rb/anycable.svg)](https://rubygems.org/gems/anycable)
3
+ [![Build](https://github.com/anycable/anycable/workflows/Build/badge.svg)](https://github.com/anycable/anycable/actions)
2
4
  [![Gitter](https://img.shields.io/badge/gitter-join%20chat%20%E2%86%92-brightgreen.svg)](https://gitter.im/anycable/Lobby)
3
- [![Documentation](https://img.shields.io/badge/docs-link-brightgreen.svg)](https://docs.anycable.io)
5
+ [![Documentation](https://img.shields.io/badge/docs-link-brightgreen.svg)](https://docs.anycable.io/v1)
4
6
 
5
7
  # AnyCable
6
8
 
7
9
  <img align="right" height="150" width="129"
8
10
  title="AnyCable logo" src="https://docs.anycable.io/assets/images/logo.svg">
9
11
 
10
- AnyCable allows you to use any WebSocket server (written in any language) as a replacement for your Ruby server (such as Faye, ActionCable, etc).
12
+ AnyCable allows you to use any WebSocket server (written in any language) as a replacement for your Ruby server (such as Faye, Action Cable, etc).
11
13
 
12
- AnyCable uses ActionCable protocol, so you can use ActionCable [JavaScript client](https://www.npmjs.com/package/actioncable) without any monkey-patching.
14
+ AnyCable uses the same protocol as ActionCable, so you can use its [JavaScript client](https://www.npmjs.com/package/actioncable) without any monkey-patching.
15
+
16
+ **Important** This is a readme for the upcoming v1.0 release. For v0.6.x see the readme from the [0-6-stable](https://github.com/anycable/anycable/tree/0-6-stable) branch.
13
17
 
14
18
  <a href="https://evilmartians.com/">
15
19
  <img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54"></a>
16
20
 
17
21
  ## Requirements
18
22
 
19
- - Ruby >= 2.4
20
- - Redis (for brodcasting, [discuss other options](https://github.com/anycable/anycable/issues/2) with us!)
23
+ - Ruby >= 2.5
24
+ - Redis (for broadcasting **in production**, [discuss other options](https://github.com/anycable/anycable/issues/2) with us!)
21
25
 
22
26
  ## Usage
23
27
 
24
- Check out our 📑 [Documentation](https://docs.anycable.io).
28
+ Check out our 📑 [Documentation](https://docs.anycable.io/v1).
25
29
 
26
30
  ## Links
27
31
 
@@ -43,31 +47,33 @@ Check out our 📑 [Documentation](https://docs.anycable.io).
43
47
 
44
48
  - RailsClub Moscow 2016 [slides](https://speakerdeck.com/palkan/railsclub-moscow-2016-anycable) and [video](https://www.youtube.com/watch?v=-k7GQKuBevY&list=PLiWUIs1hSNeOXZhotgDX7Y7qBsr24cu7o&index=4) (RU)
45
49
 
46
- ## Compatible WebSocket servers
47
-
48
- - [AnyCable Go](https://github.com/anycable/anycable-go)
49
- - [ErlyCable](https://github.com/anycable/erlycable)
50
+ ## Building
50
51
 
51
- ## Build
52
+ ### Generating gRPC files from `.proto`
52
53
 
53
54
  - Install required GRPC gems:
54
55
 
55
- ```
56
+ ```sh
56
57
  gem install grpc
57
58
  gem install grpc-tools
58
59
  ```
59
60
 
60
61
  - Re-generate GRPC files (if necessary):
61
62
 
62
- ```
63
+ ```sh
63
64
  make
64
65
  ```
65
66
 
66
67
  ## Contributing
67
68
 
68
- Bug reports and pull requests are welcome on GitHub at https://github.com/anycable/anycable.
69
+ Bug reports and pull requests are welcome on GitHub at [https://github.com/anycable/anycable](https://github.com/anycable/anycable).
69
70
 
70
71
  Please, provide reproduction script (using [this template](https://github.com/anycable/anycable/blob/master/etc/bug_report_template.rb)) when submitting bugs if possible.
71
72
 
72
73
  ## License
74
+
73
75
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
76
+
77
+ ## Security Contact
78
+
79
+ To report a security vulnerability, please contact us at `anycable@evilmartians.com`. We will coordinate the fix and disclosure.
@@ -56,14 +56,6 @@ module AnyCable
56
56
  ExceptionsHandling << block
57
57
  end
58
58
 
59
- def error_handlers
60
- warn <<~DEPRECATION
61
- Using `AnyCable.error_handlers` is deprecated!
62
- Please, use `AnyCable.capture_exception` instead.
63
- DEPRECATION
64
- ExceptionsHandling
65
- end
66
-
67
59
  # Register a callback to be invoked before
68
60
  # the server starts
69
61
  def configure_server(&block)
@@ -75,7 +67,7 @@ module AnyCable
75
67
  end
76
68
 
77
69
  def broadcast_adapter
78
- self.broadcast_adapter = :redis unless instance_variable_defined?(:@broadcast_adapter)
70
+ self.broadcast_adapter = AnyCable.config.broadcast_adapter.to_sym unless instance_variable_defined?(:@broadcast_adapter)
79
71
  @broadcast_adapter
80
72
  end
81
73
 
@@ -103,8 +95,7 @@ module AnyCable
103
95
  attr_writer :middleware
104
96
  end
105
97
 
98
+ require "anycable/middlewares/check_version"
99
+
106
100
  self.middleware = MiddlewareChain.new
107
101
  end
108
-
109
- # Backward compatibility
110
- Anycable = AnyCable
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "anycable/broadcast_adapters/base"
4
+
3
5
  module AnyCable
4
6
  module BroadcastAdapters # :nodoc:
5
7
  module_function
@@ -17,16 +19,16 @@ module AnyCable
17
19
  # We couldn't require the adapter itself.
18
20
  if e.path == path_to_adapter
19
21
  raise e.class, "Couldn't load the '#{adapter}' broadcast adapter for AnyCable",
20
- e.backtrace
22
+ e.backtrace
21
23
  # Bubbled up from the adapter require.
22
24
  else
23
25
  raise e.class, "Error loading the '#{adapter}' broadcast adapter for AnyCable",
24
- e.backtrace
26
+ e.backtrace
25
27
  end
26
28
  end
27
29
  end
28
30
 
29
- BroadcastAdapters.const_get(adapter_class_name, false).new(options || {})
31
+ BroadcastAdapters.const_get(adapter_class_name, false).new(**(options || {}))
30
32
  end
31
33
  # rubocop: enable Metrics/AbcSize, Metrics/MethodLength
32
34
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AnyCable
4
+ module BroadcastAdapters
5
+ class Base
6
+ def raw_broadcast(_data)
7
+ raise NotImplementedError
8
+ end
9
+
10
+ def broadcast(stream, payload)
11
+ raw_broadcast({stream: stream, data: payload}.to_json)
12
+ end
13
+
14
+ def broadcast_command(command, **payload)
15
+ raw_broadcast({command: command, payload: payload}.to_json)
16
+ end
17
+
18
+ def announce!
19
+ logger.info "Broadcasting via #{self.class.name}"
20
+ end
21
+
22
+ private
23
+
24
+ def logger
25
+ AnyCable.logger
26
+ end
27
+ end
28
+ end
29
+ end