Class: Warren::Handler::Broadcast::Channel

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/warren/handler/broadcast.rb

Overview

Wraps a Bunny::Channel

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bun_channel, routing_key_prefix:, exchange: nil) ⇒ Channel

Returns a new instance of Channel.



24
25
26
27
28
29
# File 'lib/warren/handler/broadcast.rb', line 24

def initialize(bun_channel, routing_key_prefix:, exchange: nil)
  @bun_channel = bun_channel
  @exchange_name = exchange
  @routing_key_prefix = routing_key_prefix
  @routing_key_template = Handler.routing_key_template(routing_key_prefix)
end

Instance Attribute Details

#routing_key_prefixObject (readonly)

Returns the value of attribute routing_key_prefix.



20
21
22
# File 'lib/warren/handler/broadcast.rb', line 20

def routing_key_prefix
  @routing_key_prefix
end

Instance Method Details

#<<(message) ⇒ Warren::Handler::Broadcast::Channel

Publishes ‘message` to the configured exchange

Parameters:

  • message (#routing_key, #payload)

    A message should respond to routing_key and payload. @see Warren::Message::Full

Returns:



38
39
40
# File 'lib/warren/handler/broadcast.rb', line 38

def <<(message)
  publish(message)
end

#publish(message, exchange: configured_exchange) ⇒ Warren::Handler::Broadcast::Channel

Publishes ‘message` to `exchange` (Defaults to configured exchange)

Parameters:

  • message (#routing_key, #payload)

    A message should respond to routing_key and payload. @see Warren::Message::Full

  • exchange (Bunny::Exchange) (defaults to: configured_exchange)

    The exchange to publish to

Returns:



50
51
52
53
# File 'lib/warren/handler/broadcast.rb', line 50

def publish(message, exchange: configured_exchange)
  exchange.publish(message.payload, routing_key: key_for(message), headers: message.headers)
  self
end