anycable 0.6.4 → 1.0.0.rc2

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