class EventQ::RabbitMq::SubscriptionManager
Public Class Methods
new(options = {})
click to toggle source
# File lib/eventq_rabbitmq/rabbitmq_subscription_manager.rb, line 5 def initialize(options = {}) if options[:client] == nil raise ':client (QueueClient) must be specified.'.freeze end @client = options[:client] @queue_manager = QueueManager.new @event_raised_exchange = EventQ::EventRaisedExchange.new end
Public Instance Methods
subscribe(event_type, queue)
click to toggle source
# File lib/eventq_rabbitmq/rabbitmq_subscription_manager.rb, line 14 def subscribe(event_type, queue) _event_type = EventQ.create_event_type(event_type) connection = @client.get_connection channel = connection.create_channel queue = @queue_manager.get_queue(channel, queue) exchange = @queue_manager.get_exchange(channel, @event_raised_exchange) queue.bind(exchange, :routing_key => _event_type) channel.close connection.close EventQ.logger.debug do "[#{self.class} #subscribe] - Subscribing queue: #{queue.name} to Exchange: #{_event_type}" end return true end
unsubscribe(queue)
click to toggle source
# File lib/eventq_rabbitmq/rabbitmq_subscription_manager.rb, line 36 def unsubscribe(queue) connection = @client.get_connection channel = connection.create_channel queue = @queue_manager.get_queue(channel, queue) exchange = @queue_manager.get_exchange(channel, @event_raised_exchange) queue.unbind(exchange) channel.close connection.close return true end