Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 19th, 2012  |  syntax: None  |  size: 0.88 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # you'll need to create a queue for the future messages.
  2. # here I'll use one called '/queue/futures'
  3.  
  4. # on the 'client' side:
  5. correlation_id = 'some unique id'
  6. future = TorqueBox::Messaging::Future.new( '/queue/futures', :correlation_id => correlation_id )
  7.  
  8. message = { :some => 'data', :id => correlation_id }
  9. @some_queue.publish( message )
  10.  
  11. #in the processor for @some_queue:
  12. TorqueBox::Messaging::FutureResponder.new( '/queue/futures', :correlation_id => message[:id]).respond do
  13.   # do the processing here - started, error, and the final return value will automatically be sent to the future
  14.  
  15.   # you can update the future status via:
  16.   future.status = 123
  17.  
  18.   # return a value
  19.   my_computed_value
  20. end
  21.  
  22.  
  23. # docs for Future: http://torquebox.org/2x/builds/yardocs/TorqueBox/Messaging/Future.html
  24. # docs for FutureResponder: http://torquebox.org/2x/builds/yardocs/TorqueBox/Messaging/FutureResponder.html