anycable-core 1.2.3 → 1.2.4

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: 3ae8ddced1365e350a744545ed12da6e42fffbaa3f58d40b0f9d83598077a88a
4
- data.tar.gz: 6637778d168c99c19a760a635455496ee121dfbbe0fd2472a3a29c4311ce3f7d
3
+ metadata.gz: 43353c30169b14234846a634a2f6e2cf9b8c205725752fcc9de78ed088e2432a
4
+ data.tar.gz: aa0b65f611dd8598b230d152f4b51ddfbdbd92c020081d957ab3f18179c6623f
5
5
  SHA512:
6
- metadata.gz: 3446218216fc8c7b76a0ddd249a8976afe8f9ddf83cdd4714bc29a94a2037caa066c5cae02bcb4a8109fd64555f80b871a4c718d059ec6382e814e9b7cc11ff0
7
- data.tar.gz: 3711df758ce8d1963f158371f5c80a06757ffd3b392acf28cbec79652abe6d61e821800ddd6f2054310d2082a651263bcbe56bfb56a5af11dfc1bbdbe40044e8
6
+ metadata.gz: 6fc3a9531075ec9da6ba4c7dc0e2e00f863829930f80a8b794e40aad13215db134c6195619d272188032502c6ae123f3567d781168580e1eb718d200042910b3
7
+ data.tar.gz: b7d91672f1976952a40315d92956f0d5970947e89d85e6e94a31240e3428e63c56093c173236ef46f25f5da47d5030cfd5576cdce8c248600a9959ceaa5e8145
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 1.2.4 (2022-08-10)
6
+
7
+ - Add NATS pub/sub adapter. ([@palkan][])
8
+
9
+ - Setting the redis adapter to use the ruby driver. ([@smasry][])
10
+
5
11
  ## 1.2.3 (2022-04-20)
6
12
 
7
13
  - Pass unique connection id (_session id_) in the `anycable.sid` Rack env field. ([@palkan][])
@@ -124,3 +130,4 @@ See [Changelog](https://github.com/anycable/anycable/blob/0-6-stable/CHANGELOG.m
124
130
  [@palkan]: https://github.com/palkan
125
131
  [@sponomarev]: https://github.com/sponomarev
126
132
  [@bibendi]: https://github.com/bibendi
133
+ [@smasry]: https://github.com/smasry
@@ -10,7 +10,7 @@ module AnyCable
10
10
  #
11
11
  # Example:
12
12
  #
13
- # AnyCable.broadast_adapter = :http
13
+ # AnyCable.broadcast_adapter = :http
14
14
  #
15
15
  # It uses configuration from global AnyCable config
16
16
  # by default.
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require "nats/client"
5
+ rescue LoadError
6
+ raise "Please, install the nats-pure gem to use NATS broadcast adapter"
7
+ end
8
+
9
+ require "json"
10
+
11
+ module AnyCable
12
+ module BroadcastAdapters
13
+ # NATS adapter for broadcasting.
14
+ #
15
+ # Example:
16
+ #
17
+ # AnyCable.broadcast_adapter = :nats
18
+ #
19
+ # It uses NATS configuration from global AnyCable config
20
+ # by default.
21
+ #
22
+ # You can override these params:
23
+ #
24
+ # AnyCable.broadcast_adapter = :nats, servers: "nats://my_nats:4242", channel: "_any_cable_"
25
+ class Nats < Base
26
+ attr_reader :nats_conn, :channel
27
+
28
+ def initialize(
29
+ channel: AnyCable.config.nats_channel,
30
+ **options
31
+ )
32
+ options = AnyCable.config.to_nats_params.merge(options)
33
+ @nats_conn = ::NATS.connect(nil, options)
34
+ @channel = channel
35
+ end
36
+
37
+ def raw_broadcast(payload)
38
+ nats_conn.publish(channel, payload)
39
+ end
40
+
41
+ def announce!
42
+ logger.info "Broadcasting NATS channel: #{channel}"
43
+ end
44
+ end
45
+ end
46
+ end
@@ -3,7 +3,7 @@
3
3
  begin
4
4
  require "redis"
5
5
  rescue LoadError
6
- raise "Please, install redis gem to use Redis broadcast adapter"
6
+ raise "Please, install the redis gem to use Redis broadcast adapter"
7
7
  end
8
8
 
9
9
  require "json"
@@ -14,7 +14,7 @@ module AnyCable
14
14
  #
15
15
  # Example:
16
16
  #
17
- # AnyCable.broadast_adapter = :redis
17
+ # AnyCable.broadcast_adapter = :redis
18
18
  #
19
19
  # It uses Redis configuration from global AnyCable config
20
20
  # by default.
@@ -30,6 +30,7 @@ module AnyCable
30
30
  **options
31
31
  )
32
32
  options = AnyCable.config.to_redis_params.merge(options)
33
+ options[:driver] = :ruby
33
34
  @redis_conn = ::Redis.new(**options)
34
35
  @channel = channel
35
36
  end
data/lib/anycable/cli.rb CHANGED
@@ -121,7 +121,7 @@ module AnyCable
121
121
  def wait_till_terminated
122
122
  self_read = setup_signals
123
123
 
124
- while readable_io = IO.select([self_read]) # rubocop:disable Lint/AssignmentInCondition,Lint/IncompatibleIoSelectWithFiberScheduler
124
+ while readable_io = IO.select([self_read]) # rubocop:disable Lint/AssignmentInCondition
125
125
  signal = readable_io.first[0].gets.strip
126
126
  raise Interrupt, "SIG#{signal} received"
127
127
  end
@@ -29,6 +29,12 @@ module AnyCable
29
29
  redis_sentinels: nil,
30
30
  redis_channel: "__anycable__",
31
31
 
32
+ ### NATS options
33
+ nats_servers: "nats://localhost:4222",
34
+ nats_channel: "__anycable__",
35
+ nats_dont_randomize_servers: false,
36
+ nats_options: {},
37
+
32
38
  ### HTTP broadcasting options
33
39
  http_broadcast_url: "http://localhost:8090/_broadcast",
34
40
  http_broadcast_secret: nil,
@@ -48,10 +54,17 @@ module AnyCable
48
54
  )
49
55
 
50
56
  if respond_to?(:coerce_types)
51
- coerce_types redis_sentinels: {type: nil, array: true}, debug: :boolean, version_check_enabled: :boolean
57
+ coerce_types(
58
+ redis_sentinels: {type: nil, array: true},
59
+ nats_servers: {type: nil, array: true},
60
+ nats_dont_randomize_servers: :boolean,
61
+ debug: :boolean,
62
+ version_check_enabled: :boolean
63
+ )
52
64
  end
53
65
 
54
- flag_options :debug
66
+ flag_options :debug, :nats_dont_randomize_servers
67
+ ignore_options :nats_options
55
68
 
56
69
  on_load do
57
70
  # @type self : AnyCable::Config
@@ -82,6 +95,11 @@ module AnyCable
82
95
  --redis-channel=name Redis channel for broadcasting, default: "__anycable__"
83
96
  --redis-sentinels=<...hosts> Redis Sentinel followers addresses (as a comma-separated list), default: nil
84
97
 
98
+ NATS PUB/SUB
99
+ --nats-servers=<...addresses> NATS servers for pub/sub, default: "nats://localhost:4222"
100
+ --nats-channel=name NATS channel for broadcasting, default: "__anycable__"
101
+ --nats-dont-randomize-servers Pass this option to disable NATS servers randomization during (re-)connect
102
+
85
103
  HTTP PUB/SUB
86
104
  --http-broadcast-url HTTP pub/sub endpoint URL, default: "http://localhost:8090/_broadcast"
87
105
  --http-broadcast-secret HTTP pub/sub authorization secret, default: <none> (disabled)
@@ -107,6 +125,14 @@ module AnyCable
107
125
  end
108
126
  end
109
127
 
128
+ # Build options for NATS.connect
129
+ def to_nats_params
130
+ {
131
+ servers: Array(nats_servers),
132
+ dont_randomize_servers: nats_dont_randomize_servers
133
+ }.merge(nats_options)
134
+ end
135
+
110
136
  # Build HTTP health server parameters
111
137
  def to_http_health_params
112
138
  {
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AnyCable
4
- VERSION = "1.2.3"
4
+ VERSION = "1.2.4"
5
5
  end
@@ -0,0 +1,10 @@
1
+ module AnyCable
2
+ module BroadcastAdapters
3
+ class Nats < Base
4
+ attr_reader nats_conn: untyped
5
+ attr_reader channel: String
6
+
7
+ def initialize: (?channel: String channel, **untyped options) -> void
8
+ end
9
+ end
10
+ end
@@ -8,6 +8,14 @@ module AnyCable
8
8
  def redis_sentinels=: (Array[String]) -> void
9
9
  def redis_channel: () -> String
10
10
  def redis_channel=: (String) -> void
11
+ def nats_servers: () -> Array[String]
12
+ def nats_servers=: (Array[String]) -> void
13
+ def nats_channel: () -> String
14
+ def nats_channel=: (String) -> void
15
+ def nats_dont_randomize_servers: () -> bool
16
+ def nats_dont_randomize_servers=: (bool) -> void
17
+ def nats_options: () -> Hash[untyped, untyped]
18
+ def nats_options=: (Hash[untyped, untyped]) -> void
11
19
  def http_broadcast_url: () -> String
12
20
  def http_broadcast_url=: (String) -> void
13
21
  def http_broadcast_secret: () -> String?
@@ -38,6 +46,7 @@ module AnyCable
38
46
  def http_health_port_provided?: () -> bool
39
47
  def to_redis_params: () -> { url: String, sentinels: Array[untyped]?, ssl_params: Hash[Symbol, untyped]? }
40
48
  def to_http_health_params: () -> { port: Integer?, path: String }
49
+ def to_nats_params: () -> Hash[Symbol, untyped]
41
50
 
42
51
  private
43
52
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anycable-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - palkan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-20 00:00:00.000000000 Z
11
+ date: 2022-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: anyway_config
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '4.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: nats-pure
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: bundler
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -157,6 +171,7 @@ files:
157
171
  - lib/anycable/broadcast_adapters.rb
158
172
  - lib/anycable/broadcast_adapters/base.rb
159
173
  - lib/anycable/broadcast_adapters/http.rb
174
+ - lib/anycable/broadcast_adapters/nats.rb
160
175
  - lib/anycable/broadcast_adapters/redis.rb
161
176
  - lib/anycable/cli.rb
162
177
  - lib/anycable/config.rb
@@ -186,6 +201,7 @@ files:
186
201
  - sig/anycable/broadcast_adapters.rbs
187
202
  - sig/anycable/broadcast_adapters/base.rbs
188
203
  - sig/anycable/broadcast_adapters/http.rbs
204
+ - sig/anycable/broadcast_adapters/nats.rbs
189
205
  - sig/anycable/broadcast_adapters/redis.rbs
190
206
  - sig/anycable/cli.rbs
191
207
  - sig/anycable/config.rbs
@@ -232,7 +248,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
232
248
  - !ruby/object:Gem::Version
233
249
  version: '0'
234
250
  requirements: []
235
- rubygems_version: 3.3.7
251
+ rubygems_version: 3.3.11
236
252
  signing_key:
237
253
  specification_version: 4
238
254
  summary: AnyCable core RPC implementation