Devanchya has asked for the wisdom of the Perl Monks concerning the following question:

I am passing data from an XML POE::Component (internal vendor app) and sending this to a POE::Component::JobQueue.

I can get the message as far as 'make_a_worker' which is where the new POE::Session->create lives. I can not get this message into that session as the data for my event.

The second session is to allow me to run a number of queues at the same time dealing with the data. From inside I will be firing a Wheel to perform some very heavy CPU data work.

Looking on line, etc, I have not found a solution that seems to work.

POE::Component::JobQueue->spawn ( Alias => 'MyQueue', WorkerLimit => 3, Worker => \&make_a_worker, Passive => { }, ); ### # Job Queue Items ### sub make_a_worker { my ( $postback, $message ) = @_; POE::Session->create( inline_states => { _start => \&start_message_process, process_message => \&process_message, delay_test => \&delay_test, _end => \&end_message_process, }, ); } sub enqueue_job { my ($kernel, $session, $job) = @_[ KERNEL, SESSION, ARG0 ]; print "-enqueue_job: -- Session: ", $session->ID, " message\n"; $kernel->post( MyQueue => 'enqueue', #'remove_message', 'test_msg', $job ); } sub got_message { my ($kernel, $session, $heap, $preargs, $postargs) = @_[KERNEL, SE +SSION, HEAP, ARG0, ARG1]; $kernel->yield( enqueue_job => $postargs->[0] ); return 1; }
Even smart people are dumb in most things...

Replies are listed 'Best First'.
Re: POE: Passing data from Session to Queue to New Session
by rcaputo (Chaplain) on Sep 02, 2008 at 16:35 UTC

    Will the args or heap parameter to POE::Session->create() be enough? That will let you pass $message into the session's _start handler.

      This has been edited since I found my issue. Yes passing the Args works. I needed to change how I thought of the args:
      sub make_a_worker { my ( $postback, $message ) = @_; POE::Session->create( inline_states => { _start => \&start_message_process, process_message => \&process_message, delay_test => \&delay_test, _end => \&end_message_process, }, args => [ $message ], ); } sub start_message_process { my ($kernel, $session, $heap, @args) = @_[KERNEL, SE +SSION, HEAP, ARG0 .. $#_ ]; $kernel->yield( process_message => $postargs->[0] ); }
      This appears to work. I will confirm on my end with a longer example.
      Even smart people are dumb in most things...