anycable 0.6.5 → 1.0.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: cb889c8917f8196bd4323767a9d73774a47d9d73d5b76ce98b601082df456d88
4
- data.tar.gz: 64946890d603cb9395863d93bb146d7a15011062fab46e2ee5a1d6e929d93880
3
+ metadata.gz: 56b2cba3d3cfba9af5c99d54351b9228a3a61e525ae7c7708e4d5859e2a85ddf
4
+ data.tar.gz: db911543cf64b3a56cebf097af09e5b64d248bc7da3ee170a06654ababe3734b
5
5
  SHA512:
6
- metadata.gz: bffef6466c0368d6950a2a46d5b80840c20954c097cbb05cbfab2a31d578d5ded652d23d612fd47806d1e0720d6e0c4f1fd986c5051c21f35bf39e3660f3d32e
7
- data.tar.gz: f738b1c94a96aada66bcfd40e51534c7d3917e209f05f3c5f01bd80afa1300ee51973e8b2bf1524a3260481549fc2462458f8d68e97d0eb34b30599dde626bf7
6
+ metadata.gz: 4e7d41fd2a41d03b3cd3137b64e86dd04df39cc95fa2639590e6f2fef95e1b87791d0ce6b06fa2922f72f5da06e8b9ad8c64e0b42511d8405cb6104fa622c326
7
+ data.tar.gz: 538f118f77c1cf56235a4b05cc4f77231736f21f78db63684cf42abd253094fbfde2da34b44f82fd9dfcc4537366efe4c98d287447e904e0197599073d66d6ae
@@ -2,266 +2,50 @@
2
2
 
3
3
  ## master
4
4
 
5
- ## 0.6.5 (2020-04-01)
5
+ ## 1.0.0 (2020-07-01)
6
6
 
7
- - Relax `anyway_config` dependency. ([@palkan][])
7
+ - Add `embedded` option to CLI runner. ([@palkan][])
8
8
 
9
- ## 0.6.4 (2020-01-24)
9
+ - Add `Env#istate` and `EnvResponse#istate` to store channel state. ([@palkan][])
10
10
 
11
- - Fix Ruby 2.7 warnings. ([@palkan][])
11
+ That would allow to mimic instance variables usage in Action Cable channels.
12
12
 
13
- Add `REMOTE_ADDR` socket env variable using a synthetic header passed from a websocket
14
- server. ([@sponomarev][])
13
+ - Add `CommandResponse#stopped_streams` to support unsubscribing from particular broadcastings. ([@palkan])
15
14
 
16
- Recreating a request object in your custom connection factory using `Rack::Request` or
17
- `ActionDispatch::Request` (already implemented in [anycable-rails](https://github.com/anycable/anycable-rails))
18
- gives you an access to `request.ip` with the properly set IP address.
15
+ `Socket#unsubscribe` is now implemented as well.
19
16
 
20
- - Align socket env to be more compatibile with Rack Spec ([@sponomarev][])
17
+ - Add `AnyCable.broadcast_adapter#broadcast_command` method. ([@palkan][])
21
18
 
22
- Provide as much env details as possible to be able to reconstruct the full
23
- request object in a custom connection factory.
19
+ It could be used to send commands to WS server (e.g., remote disconnect).
24
20
 
25
- ## 0.6.3 (2019-03-26)
21
+ - Add `:http` broadcasting adapter. ([@palkan][])
26
22
 
27
- - Relax `redis` gem version requirement. ([@palkan][])
23
+ - **RPC schema has changed**. ([@palkan][])
28
24
 
29
- Use the same restriction as Action Cable does (`>= 3`).
25
+ Using `anycable-go` v1.x is required.
30
26
 
31
- ## 0.6.2 (2019-03-15)
27
+ - **Ruby 2.5+ is required**. ([@palkan][])
32
28
 
33
- - Add GRPC service method name and message content to exception notifications ([@sponomarev][])
29
+ - Added RPC proto version check. ([@palkan][])
34
30
 
35
- `Anycable.capture_exception` allows accessing GRPC service method name and message content
36
- on which an exception was captured. It can be used for exceptions grouping in your tracker and
37
- providing additional data to investigate a root of a problem.
31
+ Server must sent `protov` metadata with the supported versions (comma-separated list). If there is no matching version an exception is raised.
38
32
 
39
- Example:
33
+ Current RPC proto version is **v1**.
40
34
 
41
- ```ruby
42
- AnyCable.capture_exception do |ex, method, message|
43
- Honeybadger.notify(ex, component: "any_cable", action: method, params: message)
44
- end
45
- ```
35
+ - Added `request` support to channels. ([@palkan][])
46
36
 
47
- Usage of a handler proc with just a single argument is preserved for the sake of compatibility.
37
+ Now you can access `request` object in channels, too (e.g., to read headers/cookies/URL/etc).
48
38
 
49
- - Add deprecation warning to default host usage ([@sponomarev][])
39
+ - Change default server address from `[::]:50051` to `127.0.0.1:50051`. ([@palkan][])
50
40
 
51
- Exposing AnyCable publicly is considered to be harmful and planned to be changed
52
- in future versions.
41
+ See [#71](https://github.com/anycable/anycable/pull/71).
53
42
 
54
- - Allow running the server as a detachable daemon ([@sponomarev][])
43
+ - Fix building Redis Sentinel config. ([@palkan][])
55
44
 
56
- Server is fully managed by the binary itself.
45
+ ---
57
46
 
58
- ```
59
- # Start anycable daemon
60
- $ bundle exec anycabled start
61
-
62
- # Pass cli options to anycable through daemon. Separate daemon options and anycable options with `--`
63
- $ bundle exec anycabled start -- --rpc-host 127.0.0.1:31337
64
-
65
- # Stop anycable daemon
66
- $ bundle exec anycabled stop
67
-
68
- # See more anycable daemon options
69
- $ bundle exec anycabled
70
- ```
71
-
72
- ## 0.6.1 (2019-01-05)
73
-
74
- - [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][])
75
-
76
- ## 0.6.0 (2018-11-15)
77
-
78
- ### Features
79
-
80
- #### Broadcast adapters
81
-
82
- AnyCable allows you to use custom broadcasting adapters (Redis is used by default):
83
-
84
- ```ruby
85
- # Specify by name (tries to load `AnyCable::BroadcastAdapters::MyAdapter` from
86
- # "anycable/broadcast_adapters/my_adapter")
87
- AnyCable.broadcast_adapter = :my_adapter, { option: "value" }
88
- # or provide an instance (should respond_to #broadcast)
89
- AnyCable.broadcast_adapter = MyAdapter.new
90
- ```
91
-
92
- **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.
93
-
94
- #### CLI
95
-
96
- AnyCable now ships with a CLI–`anycable`.
97
-
98
- Use it to run a gRPC server:
99
-
100
- ```sh
101
- # run anycable and load app from app.rb
102
- bundle exec anycable -r app.rb
103
- # or
104
- bundle exec anycable --require app.rb
105
- ```
106
-
107
- All configuration options are also supported as CLI options (see `anycable -h` for more information).
108
-
109
- The only required options is the application file to load (`-r/--require`).
110
-
111
- You can omit it if you want to load an app form `./config/environment.rb` (e.g. with Rails) or `./config/anycable.rb`.
112
-
113
- AnyCable CLI also allows you to run a separate command (process) from within a RPC server:
114
-
115
- ```sh
116
- $ bundle exec anycable --server-command "anycable-go -p 3334"
117
- ```
118
-
119
- #### Configuration
120
-
121
- - Default server host is changed from `localhost:50051` to `0.0.0.0:50051`
122
- - Expose gRPC server parameters via `rpc_*` config params:
123
-
124
- ```ruby
125
- AnyCable.configure do |config|
126
- config.rpc_pool_size = 120
127
- config.rpc_max_waiting_requests = 10
128
- # etc
129
- end
130
- ```
131
- - `REDIS_URL` env is used by default if present (and no `ANYCABLE_REDIS_URL` specified)
132
- - Make HTTP health check url configurable
133
- - Add ability to pass Redis Sentinel config as array of string.
134
-
135
- Now it's possible to pass Sentinel configuration via env vars:
136
-
137
- ```sh
138
- ANYCABLE_REDIS_SENTINELS=127.0.0.1:26380,127.0.0.1:26381 bundle exec anycable
139
- ```
140
-
141
- #### Other
142
-
143
- - Added middlewares support
144
-
145
- See [docs](https://docs.anycable.io/#/./middlewares).
146
-
147
- - Added gRPC health checker.
148
-
149
- See [docs](https://docs.anycable.io/#/./health_checking).
150
-
151
- - Added hook to run code only within RPC server context.
152
-
153
- Use `AnyCable.configure_server { ... }` to run code only when RPC server is running.
154
-
155
- ### API changes
156
-
157
- **NOTE**: the old API is still working but deprecated (you'll see a notice).
158
-
159
- - Use `AnyCable` instead of `Anycable`
160
-
161
- - New API for registering error handlers:
162
-
163
- ```ruby
164
- AnyCable.capture_exception do |ex|
165
- Honeybadger.notify(ex)
166
- end
167
- ```
168
-
169
- - `AnyCable::Server.start` is deprecated
170
-
171
-
172
- ## 0.5.2 (2018-09-06)
173
-
174
- - [#48](https://github.com/anycable/anycable/pull/48) Add HTTP health server ([@DarthSim][])
175
-
176
- ## 0.5.1 (2018-06-13)
177
-
178
- Minor fixes.
179
-
180
- ## 0.5.0 (2017-10-21)
181
-
182
- - [#2](https://github.com/anycable/anycable/issues/2) Add support for [Redis Sentinel](https://redis.io/topics/sentinel). ([@accessd][])
183
-
184
- - [#28](https://github.com/anycable/anycable/issues/28) Support arbitrary headers. ([@palkan][])
185
-
186
- Previously we hardcoded only "Cookie" header. Now we add all passed headers by WebSocket server to request env.
187
-
188
- - [#27](https://github.com/anycable/anycable/issues/27) Add `error_msg` to RPC responses. ([@palkan][])
189
-
190
- Now RPC responses has 3 statuses:
191
-
192
- - `SUCCESS` – successful request, operation succeed
193
- - `FAILURE` – successful request, operation failed (e.g. authentication failed)
194
- - `ERROR` – request failed (exception raised).
195
-
196
- We provide `error_msg` only when request status is `ERROR`.
197
-
198
- - [#25](https://github.com/anycable/anycable/issues/25) Improve logging and exceptions handling. ([@palkan][])
199
-
200
- Default logger logs to STDOUT with `info` level by default but can be configured to log to file with
201
- any severity.
202
-
203
- GRPC logging is turned off by default (can be turned on through `log_grpc` configuration parameter).
204
-
205
- `ANYCABLE_DEBUG=1` acts as a shortcut to set `debug` level and turn on GRPC logging.
206
-
207
- Now it's possible to add custom exception handlers (e.g. to notify external exception tracking services).
208
-
209
- More on [Wiki](https://github.com/anycable/anycable/wiki/Logging-&-Exceptions-Handling).
210
-
211
- ## 0.4.6 (2017-05-20)
212
-
213
- - Add `Anycable::Server#stop` method. ([@sadovnik][])
214
-
215
- ## 0.4.5 (2017-03-17)
216
-
217
- - Fixed #11. ([@palkan][])
218
-
219
- ## 0.4.4 (2017-03-06)
220
-
221
- - Handle `StandardError` gracefully in RPC calls. ([@palkan][])
222
-
223
- ## 0.4.3 (2017-02-18)
224
-
225
- - Update `grpc` version dependency to support Ruby 2.4. ([@palkan][])
226
-
227
- ## 0.4.2 (2017-01-28)
228
-
229
- - Change socket streaming API. ([@palkan][])
230
-
231
- Add `Socket#subscribe`, `unsubscribe` and `unsubscribe_from_all` methods.
232
-
233
- ## 0.4.1 (2017-01-24)
234
-
235
- - Introduce _fake_ socket instance to handle transmissions and streams. ([@palkan][])
236
-
237
- - Make commands handling more abstract. ([@palkan][])
238
-
239
- We now do not explicitly call channels action but use the only one entrypoing for all commands:
240
-
241
- ```ruby
242
- connection.handle_channel_command(identifier, command, data)
243
- ```
244
-
245
- This method should return `true` if command was successful and `false` otherwise.
246
-
247
- ## 0.4.0 (2017-01-22)
248
-
249
- - Refactor RPC API. ([@palkan][])
250
-
251
- Replace `Subscribe`, `Unsubscribe` and `Perform` methods with `Command` method.
252
-
253
- - Extract Rails functionality to separate gem. ([@palkan][])
254
-
255
- All Rails specifics now live here https://github.com/anycable/anycable-rails.
256
-
257
- ## 0.3.0 (2016-12-28)
258
-
259
- - Handle `Disconnect` requests. ([@palkan][])
260
-
261
- Implement `Disconnect` handler, which invokes `Connection#disconnect` (along with `Channel#unsubscribed` for each subscription).
47
+ See [Changelog](https://github.com/anycable/anycable/blob/0-6-stable/CHANGELOG.md) for versions <1.0.0.
262
48
 
263
49
  [@palkan]: https://github.com/palkan
264
- [@sadovnik]: https://github.com/sadovnik
265
- [@accessd]: https://github.com/accessd
266
- [@DarthSim]: https://github.com/DarthSim
267
50
  [@sponomarev]: https://github.com/sponomarev
51
+ [@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
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.
13
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.
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 broadcasting, [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,36 +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).
74
76
 
75
77
  ## Security Contact
76
78
 
77
- To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.
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,11 +19,11 @@ 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
@@ -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