class Hutch::Schedule::Core
Attributes
broker[R]
exchange[R]
Public Class Methods
new(broker)
click to toggle source
# File lib/hutch/schedule/core.rb, line 12 def initialize(broker) raise "Broker can`t be nil" if broker.blank? @broker = broker end
Public Instance Methods
connect!()
click to toggle source
Becareful with the sequence of initialize
# File lib/hutch/schedule/core.rb, line 18 def connect! declare_delay_exchange! declare_publisher! setup_delay_queues! end
declare_delay_exchange(ch = channel)
click to toggle source
# File lib/hutch/schedule/core.rb, line 33 def declare_delay_exchange(ch = channel) exchange_name = "#{Hutch::Config.get(:mq_exchange)}.schedule" exchange_options = { durable: true }.merge(Hutch::Config.get(:mq_exchange_options)) logger.info "using topic exchange(schedule) '#{exchange_name}'" broker.send(:with_bunny_precondition_handler, 'schedule exchange') do ch.topic(exchange_name, exchange_options) end end
declare_delay_exchange!()
click to toggle source
The exchange used by Hutch::Schedule
# File lib/hutch/schedule/core.rb, line 29 def declare_delay_exchange! @exchange = declare_delay_exchange end
declare_publisher!()
click to toggle source
# File lib/hutch/schedule/core.rb, line 24 def declare_publisher! @publisher = Hutch::Publisher.new(connection, channel, exchange) end
publish(*args)
click to toggle source
Schedule`s publisher, publish the message to schedule topic exchange
# File lib/hutch/schedule/core.rb, line 58 def publish(*args) @publisher.publish(*args) end
setup_delay_queue!(suffix)
click to toggle source
# File lib/hutch/schedule/core.rb, line 48 def setup_delay_queue!(suffix) # TODO: extract the ttl to config params props = { :'x-message-ttl' => 30.days.in_milliseconds, :'x-dead-letter-exchange' => Hutch::Config.get(:mq_exchange) } queue = broker.queue(Hutch::Schedule.delay_queue_name(suffix), props) # bind routing_key to schedule exchange queue.bind(exchange, routing_key: Hutch::Schedule.delay_routing_key(suffix)) end
setup_delay_queues!()
click to toggle source
The queue used by Hutch::Schedule
# File lib/hutch/schedule/core.rb, line 44 def setup_delay_queues! DELAY_QUEUES.map { |suffix| setup_delay_queue!(suffix) } end