Class: Jackrabbit::Client
- Inherits:
-
Object
- Object
- Jackrabbit::Client
- Defined in:
- lib/jackrabbit/client.rb
Constant Summary collapse
- InvalidExchangeType =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #bonded_queue(name, options = {}, &block) ⇒ Object
- #channel ⇒ Object
- #exchange ⇒ Object
-
#initialize(config = Jackrabbit.config) ⇒ Client
constructor
A new instance of Client.
- #publish(message, options = {}) ⇒ Object
- #queue(name, options) ⇒ Object
Constructor Details
#initialize(config = Jackrabbit.config) ⇒ Client
Returns a new instance of Client.
8 9 10 |
# File 'lib/jackrabbit/client.rb', line 8 def initialize(config = Jackrabbit.config) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/jackrabbit/client.rb', line 5 def config @config end |
Instance Method Details
#bonded_queue(name, options = {}, &block) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/jackrabbit/client.rb', line 28 def bonded_queue(name, = {}, &block) queue_opts, binding_opts, = () queue = self.queue(name, queue_opts) receiver = MessageReceiver.new(channel, &block) queue.bind(exchange, binding_opts) queue.subscribe() do |info, , payload| receiver.handle(info, , payload) end end |
#channel ⇒ Object
12 13 14 |
# File 'lib/jackrabbit/client.rb', line 12 def channel @channel ||= connection.create_channel end |
#exchange ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/jackrabbit/client.rb', line 16 def exchange if %w(fanout direct topic).include?(config.exchange_type) @exchange ||= channel.send(config.exchange_type, config.exchange_name, config.) else raise InvalidExchangeType, "The exchange type '#{config.exchange_type}' is invalid" end end |
#publish(message, options = {}) ⇒ Object
24 25 26 |
# File 'lib/jackrabbit/client.rb', line 24 def publish(, = {}) exchange.publish(, ) end |
#queue(name, options) ⇒ Object
41 42 43 |
# File 'lib/jackrabbit/client.rb', line 41 def queue(name, ) channel.queue(name, ) end |