Class: AnyCable::BroadcastAdapters::Nats
- Defined in:
- lib/anycable/broadcast_adapters/nats.rb
Overview
NATS adapter for broadcasting.
Example:
AnyCable.broadcast_adapter = :nats
It uses NATS configuration from global AnyCable config by default.
You can override these params:
AnyCable.broadcast_adapter = :nats, servers: "nats://my_nats:4242", channel: "_any_cable_"
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#nats_conn ⇒ Object
readonly
Returns the value of attribute nats_conn.
Instance Method Summary collapse
- #announce! ⇒ Object
-
#initialize(channel: AnyCable.config.nats_channel, **options) ⇒ Nats
constructor
A new instance of Nats.
- #raw_broadcast(payload) ⇒ Object
Methods inherited from Base
#batching, #batching?, #broadcast, #broadcast_command, #finish_batching, #start_batching
Constructor Details
#initialize(channel: AnyCable.config.nats_channel, **options) ⇒ Nats
Returns a new instance of Nats.
28 29 30 31 32 33 34 35 36 |
# File 'lib/anycable/broadcast_adapters/nats.rb', line 28 def initialize( channel: AnyCable.config.nats_channel, ** ) = AnyCable.config.to_nats_params.merge() @nats_conn = ::NATS.connect(nil, ) setup_listeners(nats_conn) @channel = channel end |
Instance Attribute Details
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
26 27 28 |
# File 'lib/anycable/broadcast_adapters/nats.rb', line 26 def channel @channel end |
#nats_conn ⇒ Object (readonly)
Returns the value of attribute nats_conn.
26 27 28 |
# File 'lib/anycable/broadcast_adapters/nats.rb', line 26 def nats_conn @nats_conn end |
Instance Method Details
#announce! ⇒ Object
42 43 44 |
# File 'lib/anycable/broadcast_adapters/nats.rb', line 42 def announce! logger.info "Broadcasting NATS channel: #{channel}" end |
#raw_broadcast(payload) ⇒ Object
38 39 40 |
# File 'lib/anycable/broadcast_adapters/nats.rb', line 38 def raw_broadcast(payload) nats_conn.publish(channel, payload) end |