Hey @rms2219, you should look how Laravel push the quotes. If you look at the generated JSON, you will find something like:
{"job":"Acme\\Jobs\\PushFilesJob","data":{"file_id":"1"}}
The listener then will find the "job" class and run the fire function.
Does that helps you?
@ipalaus, I suppose I should re-phrase my question...Can a Laravel application listen/consume messages from a queue for which it did not push messages to? In other words, can a Laravel app act as ONLY a listener? And if so, how do I configure it to use a particular class to handle the message processing?
Yeah, of course it can but Laravel listeners expect a concrete message. A JSON containing the class name (+ data if you want).
ipalaus said:
A JSON containing the class name (+ data if you want).
So I can setup the listener like:
php artisan queue:listen {"job" : "PATH\\TO\\MY\\PROCESSOR"}
?
No, the queue:listen will listen to the given driver. The driver knows where to fetch the jobs, if it's the Amazon SQS somehow you should push your jobs there (with the 3rd party API) and then just configure the queue to listen there. And just run php artisan queue:listen
.
ipalaus said:
No, the queue:listen will listen to the given driver. The driver knows where to fetch the jobs, if it's the Amazon SQS somehow you should push your jobs there (with the 3rd party API) and then just configure the queue to listen there. And just run
php artisan queue:listen
.
Right, so that's what I did. I pushed a message to my SQS queue via Amazon's console. So, there's a job just sitting there in the queue. My problem is, when I run php artisan queue:listen
, how can I tell the Laravel app where to send that message once it pulls it from the queue?
Are you saying that the message I push to SQS (regardless of where it's being pushed from) needs to be in the format: {"job":"Acme\Jobs\PushFilesJob","data":{"file_id":"1"}}? If so, this makes more sense. I was thinking that all I needed to do was to push data to the queue, and when I set up my listener, I'd make a connection between the listener and the class that processes the message.
ipalaus said:
That's it. You need that payload in SQS.
Thanks...I've got it now and it's working as expected. Thank you for your help.
ipalaus said:
Yeah, of course it can but Laravel listeners expect a concrete message. A JSON containing the class name (+ data if you want).
I am using Laravel 5 to accomplish the same task. My jobs (JSON) are being pushed to a beanstalkd queue from an external entity and I want to setup my Queuing system within my laravel app to just watch the queue and handle jobs from it as and when it is available. Please do help me in doing this.
PS: What should be the exact JSON structure that I need to follow for my jobs to be recognized by my laravel queue listener?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community