Class: ActionCable::SubscriptionAdapter::Nats

Inherits:
Inline
  • Object
show all
Includes:
ChannelPrefix
Defined in:
lib/action_cable/subscription_adapter/nats.rb

Overview

:nodoc:

Defined Under Namespace

Classes: Listener

Instance Method Summary collapse

Constructor Details

#initialize(server) ⇒ Nats

Returns a new instance of Nats.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/action_cable/subscription_adapter/nats.rb', line 12

def initialize(server)
  super
  nconf = server.config.cable.deep_symbolize_keys
  @nats_conn = ::NATS.connect(nconf[:url], nconf[:cluster] || {})
  @nats_conn.on_error do |e|
    @logger.error "NATS Error: #{e}"
  end

  @nats_conn.on_reconnect do
    @logger.info "NATS Reconnected to server at #{@nats_conn.connected_server}"
  end

  @nats_conn.on_disconnect do
    @logger.warn "NATS Disconnected"
  end

  @nats_conn.on_close do
    @logger.info "NATS connection close"
  end
end

Instance Method Details

#broadcast(channel, payload) ⇒ Object



33
34
35
# File 'lib/action_cable/subscription_adapter/nats.rb', line 33

def broadcast(channel, payload)
  @nats_conn.publish(channel, payload)
end