[rabbitmq-discuss] Workflow for optional data in HTTP server process?

François Beausoleil francois at teksol.info
Mon May 13 14:02:04 BST 2013


Hi!

Let's say I have data which I'd like to return to an HTTP client (browser), but is optional. When the request hits the web server process, is it expected that it would open a channel, create a server-named queue and send the request, with reply-to set to the queue? Once all processing is completed, the web server process would poll the queue for N milliseconds and return ASAP. If the reply hasn't arrived, RabbitMQ would discard it since the queue would already be destroyed.

Because the data is optional, I would assume that this workflow is as optimal as possible?

For reference, I'm talking about using Bunny in a Ruby 1.9.3 Unicorn HTTP web server. Pseudo-code:

# Ruby / Sinatra
get "/widget/:id" do
  queue = nil
  begin
    queue = bunny.queue("")
    exchange.publish(params[:id], reply_to: queue.name)

    # database code - expected to take a couple milliseconds
    @widget = # fetch from database
    # more processing

    # hopefully, by this time, the data has made it only the queue
    # and we can get it - else, we won't care
    @optional = queue.get # returns nil if no message, does not block
  finally
    queue.close if queue
  end
end

With this code, the queue is expected to live for only a few milliseconds.

Bye!
François

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4142 bytes
Desc: not available
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20130513/e387e04b/attachment.bin>


More information about the rabbitmq-discuss mailing list