lukeredpath / beanstalk-messaging

This URL has Read+Write access

lukeredpath (author)
Mon Oct 13 05:40:14 -0700 2008
commit  00e5424d273fa0f55711b79bc70e90545665491f
tree    25a16b4045453194baa87a8367dc283a9049cdaa
parent  9377427af1be1500e2d37556ca0dbc4ce71e1e02
beanstalk-messaging / README.textile
6d1d19a8 » lukeredpath 2008-07-25 Merge branch 'master' into ... 1 h1. Beanstalk Messaging Plugin for Rails
83d17e0a » lukeredpath 2008-01-09 Initial import of skeleton ... 2
6dd27d86 » jamesadam 2008-01-11 You can never have too litt... 3 The Beanstalk Messaging Plugin provides a simple interface to the +beanstalkd+ queuing
4 process.
83d17e0a » lukeredpath 2008-01-09 Initial import of skeleton ... 5
6d1d19a8 » lukeredpath 2008-07-25 Merge branch 'master' into ... 6 h2. Configuration
83d17e0a » lukeredpath 2008-01-09 Initial import of skeleton ... 7
6dd27d86 » jamesadam 2008-01-11 You can never have too litt... 8 Copy beanstalk.example.yml from the plugin config folder to your Rails config folder
9 and configure the queues that you need for your application. Use script/beanstalk to
10 start/stop/restart your beanstalkd processes.
83d17e0a » lukeredpath 2008-01-09 Initial import of skeleton ... 11
6d1d19a8 » lukeredpath 2008-07-25 Merge branch 'master' into ... 12 h2. Using the Beanstalk::QueueManager
83d17e0a » lukeredpath 2008-01-09 Initial import of skeleton ... 13
6dd27d86 » jamesadam 2008-01-11 You can never have too litt... 14 Use the Beanstalk::QueueManager class to access your queues by name, using the
15 Beanstalk::QueueManager#queue method. For example:
83d17e0a » lukeredpath 2008-01-09 Initial import of skeleton ... 16
6dd27d86 » jamesadam 2008-01-11 You can never have too litt... 17 queue_manager = BeanStalk::QueueManager.new("beanstalk-config.yml")
18 my_queue = queue_manager.queue(:my_queue)
19 my_queue << "Here's a message"
83d17e0a » lukeredpath 2008-01-09 Initial import of skeleton ... 20
6dd27d86 » jamesadam 2008-01-11 You can never have too litt... 21 In your +environment.rb+ file, you should create a single instance of a Beanstalk::QueueManager
22 using your +beanstalk.yml+ config as a global constant that you can use throughout your app. This
23 will ensure that each request to QueueManager.queue returns the same Beanstalk::Queue
24 instance. For example, you may wish to add the following to the bottom of +environment.rb+:
25
26 QUEUE_MANAGER = Beanstalk::QueueManager.new(File.join(RAILS_ROOT, 'config', 'beanstalk.yml'))
27
28 You can disable queues globally by using the Beanstalk::QueueManager#disable method to temporarily
29 disable the use of that particular queue. Beanstalk::QueueManager#disable_all disables all queues.
30 When a queue is disabled, the Beanstalk::QueueManager will return a Beanstalk::NullQueue instead of an actual
31 Beanstalk::Queue object which will handle any Beanstalk::Queue API calls silently:
32
6d1d19a8 » lukeredpath 2008-07-25 Merge branch 'master' into ... 33 <pre><code>
34 # In environment.rb
35 QUEUE_MANAGER.disable(:my_queue)
6dd27d86 » jamesadam 2008-01-11 You can never have too litt... 36
6d1d19a8 » lukeredpath 2008-07-25 Merge branch 'master' into ... 37 ## Elsewhere in your application...
38 queue = QUEUE_MANAGER.queue(:my_queue)
39 100.times { queue << "In /dev/null, noone can hear you scream..." }
40 ## Nothing actually gets sent to the beanstalkd process
41 </code></pre>
6dd27d86 » jamesadam 2008-01-11 You can never have too litt... 42
6d1d19a8 » lukeredpath 2008-07-25 Merge branch 'master' into ... 43 h2. Using Beanstalk::Queue
6dd27d86 » jamesadam 2008-01-11 You can never have too litt... 44
45 Use the Beanstalk::Queue API to push messages on to the queue and consume messages. This
46 amounts to using Beanstalk::Queue#push (or Beanstalk::Queue#<<) to add messages to the queue,
47 and Beanstalk::Queue#next_message to retrieve messages. Note that you do not need to
48 transform the data into YAML - this is performed automatically by the queue.
49
6d1d19a8 » lukeredpath 2008-07-25 Merge branch 'master' into ... 50 <pre><code>
51 queue << [1,2,3]
52 # => "---\n1\n2\n3" # YAML version ends up on the queue
53
54 queue.next_message
55 # => [1,2,3] # YAML deserialization is performed automatically
56 </code></pre>
00e5424d » lukeredpath 2008-10-13 Just a test commit 57