Class: SimpleMessaging::MessageQueue
- Inherits:
-
Object
- Object
- SimpleMessaging::MessageQueue
- Defined in:
- lib/simple_messaging/message_queue.rb
Defined Under Namespace
Class Method Summary collapse
- .driver_name ⇒ Object
- .driver_name=(driver_name) ⇒ Object
- .instance(name) ⇒ Object
-
.unregister_queue(name) ⇒ Object
Deriving classes need to implement the following methods def enqueue(message) def poll(&block) def pop(&block).
Class Method Details
.driver_name ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/simple_messaging/message_queue.rb', line 38 def self.driver_name return @driver_name if @driver_name return ENV["MESSAGING_DRIVER"].strip if ENV["MESSAGING_DRIVER"] messaging_config_file = Pathname.new(Dir.pwd).join('config', 'messaging.yml').to_s if File.exist? messaging_config_file messaging_configs = YAML.load(File.open(messaging_config_file).read) messaging_configs[self.environment]['driver'] else raise "Messaging driver isn't set" end end |
.driver_name=(driver_name) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/simple_messaging/message_queue.rb', line 13 def self.driver_name=(driver_name) if driver_name != @driver_name @driver_class = nil @queues = nil @driver_name = driver_name.to_s end end |
.instance(name) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/simple_messaging/message_queue.rb', line 21 def self.instance(name) @queues ||= {} return @queues[name] if @queues[name] @driver_class ||= case self.driver_name when 'sqs' MessageQueue::SQS when 'rabbit' MessageQueue::Rabbit else raise "Messaging driver '#{driver_name}' not implemented" end @queues[name] = @driver_class.new(name) end |
.unregister_queue(name) ⇒ Object
Deriving classes need to implement the following methods def enqueue(message) def poll(&block) def pop(&block)
9 10 11 |
# File 'lib/simple_messaging/message_queue.rb', line 9 def self.unregister_queue(name) @queues[name] = nil end |