Module: Rabbit
- Extended by:
- Rabbit
- Included in:
- Rabbit
- Defined in:
- lib/rabbit.rb,
lib/rabbit/daemon.rb,
lib/rabbit/helper.rb,
lib/rabbit/version.rb,
lib/rabbit/receiving.rb,
lib/rabbit/publishing.rb,
lib/rabbit/publishing/channels_pool.rb
Defined Under Namespace
Modules: Compressor, Daemon, Helper, Publishing, Receiving, TestHelpers Classes: Config, EventHandler
Constant Summary collapse
- InvalidConfig =
Class.new(StandardError)
- MessageNotDelivered =
Class.new(StandardError)
- VERSION =
"1.8.0"
Instance Method Summary collapse
- #config {|@config| ... } ⇒ Object
- #configure {|config| ... } ⇒ Object
- #default_queue_name(ignore_conversion: false) ⇒ Object
- #publish(routing_key: nil, event: nil, data: {}, exchange_name: [], confirm_select: true, realtime: false, headers: {}, message_id: nil, custom_queue_name: nil) ⇒ Object
- #queue_name(queue, ignore_conversion: false) ⇒ Object
- #root ⇒ Object
- #sneakers_config ⇒ Object
Instance Method Details
#config {|@config| ... } ⇒ Object
145 146 147 148 149 |
# File 'lib/rabbit.rb', line 145 def config @config ||= Config.new yield(@config) if block_given? @config end |
#configure {|config| ... } ⇒ Object
168 169 170 171 |
# File 'lib/rabbit.rb', line 168 def configure yield(config) config.validate! end |
#default_queue_name(ignore_conversion: false) ⇒ Object
210 211 212 |
# File 'lib/rabbit.rb', line 210 def default_queue_name(ignore_conversion: false) queue_name(config.default_publishing_job_queue, ignore_conversion: ignore_conversion) end |
#publish(routing_key: nil, event: nil, data: {}, exchange_name: [], confirm_select: true, realtime: false, headers: {}, message_id: nil, custom_queue_name: nil) ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/rabbit.rb', line 173 def publish( routing_key: nil, event: nil, data: {}, exchange_name: [], confirm_select: true, realtime: false, headers: {}, message_id: nil, custom_queue_name: nil ) = Publishing::Message.new( routing_key: routing_key, event: event, data: data, exchange_name: exchange_name, confirm_select: confirm_select, realtime: realtime, headers: headers, message_id: , ) job_class = config.publishing_job_class_callable publish_job_callable = job_class.is_a?(Proc) ? job_class.call : (job_class || Publishing::Job) queue_name = custom_queue_name || default_queue_name if .realtime? Publishing.publish() else publish_job_callable.set(queue: queue_name).perform_later(.to_hash) end end |
#queue_name(queue, ignore_conversion: false) ⇒ Object
205 206 207 208 |
# File 'lib/rabbit.rb', line 205 def queue_name(queue, ignore_conversion: false) return queue if ignore_conversion config.queue_name_conversion ? config.queue_name_conversion.call(queue) : queue end |
#root ⇒ Object
151 152 153 154 155 156 157 |
# File 'lib/rabbit.rb', line 151 def root if defined?(Rails) Rails.root else Pathname.new(Dir.pwd) end end |
#sneakers_config ⇒ Object
159 160 161 162 163 164 165 166 |
# File 'lib/rabbit.rb', line 159 def sneakers_config if defined?(Rails) Rails.application.config_for("sneakers") else config = YAML.load_file("config/sneakers.yml", aliases: true) config[Rabbit.config.environment.to_s].to_h.symbolize_keys end end |