[rabbitmq-discuss] forking and getting or consuming messages

Chris dmagick at gmail.com
Mon Jul 29 22:58:29 BST 2013


On 26/07/13 15:35, Michael Klishin wrote:
> Chris:
>
>> The second problem is that once all the messages are off the stack, the script exits. I'd like it to stay open and wait for more messages to come in. Is that possible using the queue->get() approach?
>
> Child processes of fork(2) need to reopen all network connections
> (not just to RabbitMQ).

Yep, I understand that.

The structure looks like this:

Parent:
  - connects to the main queue.
  - get() a message
  -- forks
  -- Fires up a separate script to deal with queue 'X'
  -- repeat for other tasks for queues 'Y' and 'Z'
  - waits for all child scripts to finish
  - exits nicely

Child (deals with its own connection to rabbit, it's a separate 
self-contained script):
  - connects to queue 'X' (this is hardcoded - separate scripts deal 
with different queues for different reasons).
  - get() a message
  -- do work
  - repeat until get() returns nothing
  - exits nicely

If I put more tasks on queue 'X' while child is already running, they 
aren't seen. Not a big deal but ideally I'd like them to be picked up 
rather than having to run the child process again. Do I need to do 
something here to make this work?

I'd also like parent to keep listening for more incoming tasks (rather 
than exiting and having to run it again). I changed this to be a 
consumer rather than using get() to fetch the messages, but then the 
forking would wait for the child to finish rather than immediately going 
to the next task. Am I missing something (should I be ack'ing the 
message straight after getting it for it to immediately go to the next?)

Thanks again.
-- 
Postgresql & php tutorials
http://www.designmagick.com/



More information about the rabbitmq-discuss mailing list