4
votes

I'm trying to set up Laravel 4.2 queue using AWS SQS and an EB Worker environment. I'm pushing the job into the queue from another server and I want the worker environment to execute it. But so far it looks like the worker tries to execute it, but for some reason gets a 405 error in the access log...

I'm trying to get a very simple test code... On the worker env. I pretty much clean Laravel installation just with queue config and stuff and this class:

class TestQueue {

    public function fire($job, $data)
    {
        File::append(storage_path().'/sqs_push.txt', $data['date']);

        $job->delete();
    }
}

Now on the main server, from where I want to push, I have this:

public function getTestQueue(){
    $data = ['date' => date('Y-m-d H:i:s')];
    $queue = \Queue::push('TestQueue', $data);
    var_dump($queue);
}

On the worker I have launched the

php artisan queue:listen

When I run that method, it adds it to the SQS queue (I can see it in the SQS console) and the worker tries to execute it, but all I see is some 405 errors in the access logs... Maybe im doing something wrong in my queue setup? Can anyone help me please?

1

1 Answers

0
votes

Error 405 stands for "MethodNotAllowed" where the specified method is not allowed against this. Since you have mentioned that Main Server successfully sends the messages to SQS (you have verified it via the console), I will provide a solution to implement a worker thread. This was taken from this repository in GitHub. Have a look at the worker.php file.

$queue = new Queue(QUEUE_NAME, unserialize(AWS_CREDENTIALS));

// Continuously poll queue for new messages and process them.
while (true) {
    $message = $queue->receive();
    if ($message) {
        try {
            $message->process();
            $queue->delete($message);
        } catch (Exception $e) {
            $queue->release($message);
            echo $e->getMessage();
        }
    } else {
        // Wait 20 seconds if no jobs in queue to minimise requests to AWS API
        sleep(20);
    }
}