Class: Ass::Server
Instance Attribute Summary collapse
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
Instance Method Summary collapse
- #exchange ⇒ Object
-
#initialize(server_exchange, q) ⇒ Server
constructor
A new instance of Server.
- #react(callback = nil, opts = nil, &block) ⇒ Object
Methods included from Callback
#build_callback_klass, #callback
Constructor Details
#initialize(server_exchange, q) ⇒ Server
Returns a new instance of Server.
167 168 169 170 |
# File 'lib/ass.rb', line 167 def initialize(server_exchange,q) @queue = q @server_exchange = server_exchange end |
Instance Attribute Details
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
172 173 174 |
# File 'lib/ass.rb', line 172 def queue @queue end |
Instance Method Details
#exchange ⇒ Object
173 174 175 |
# File 'lib/ass.rb', line 173 def exchange @server_exchange end |
#react(callback = nil, opts = nil, &block) ⇒ Object
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 204 |
# File 'lib/ass.rb', line 177 def react(callback=nil,opts=nil,&block) if block opts = callback callback = block end opts = {} if opts.nil? @callback_klass = build_callback_klass(callback) @ack = opts[:ack] @queue.subscribe(opts) do |info,payload| payload = ::Marshal.load(payload) #p [info,info.reply_to,payload] data2 = callback(info,payload) payload2 = payload.merge :data => data2 if info.routing_key == @server_exchange.name # addressed to the server's public # queue, respond to the routing_key of # the client's public queue. key = info.reply_to else # addressed to the private queue key = info.routing_key end MQ.direct(info.reply_to).publish(::Marshal.dump(payload2),:routing_key => key) if info.reply_to info.ack if @ack end self end |