我正在尝试使用上述工具运行一个简单的排队系统。
我正在让队列将消息推送到我的 Iron.IO 仪表板。所以我可以在那里看到散列消息。但是当我运行主管和 php artisan queue:listen 时,我不断收到以下错误。
exception 'IronCore\HttpException' with message 'http error: 400 | {"msg":"A reservation_id is required"}' in /var/www/rmp-connect.co.uk/vendor/iron-io/iron_core/src/IronCore.php:414
我尝试了不同版本的 IronIO,但看起来 4.* 是 Laravel 5.1 的推荐版本。
我的路线有以下几点:
Route::get('queue/export', array(
'as' => 'queue/export',
'uses' => 'ExportController@queueExport'
));
Route::post('queue/receive', array(
'as' => 'queue/receive',
'uses' => 'ExportController@receive'
));
第一个 Route 中的 ExportController 具有以下内容:
<?php
class ExportController extends Controller
{
/**
* This will send a new task to iron named “exportCSV”, and will also include the user id, company id,
* and the file name to write the results to as an array. All of this data will be passed back
* to our app, when the task is ready to be run.
*/
public function queueExport()
{
$company_id = rand(1, 100000);
$user_id = rand(1,1000000);
$exportName = 'TEST_CSV_'. rand(1,100000);
$apiClass = 'Export';
$data = ['user_id' => $user_id, 'exportName' => $exportName, $user_id => 12];
$job = (new App\Jobs\Export($data))->onQueue('connect');
$this->dispatch($job);
}
/**
* The marshal’s job is to direct the response to the proper task to be completed.
* This is based on the name we provided when we post to a queue.
* In our case, it is called 'Connect' for now.
* @return mixed
*/
public function receive()
{
//We will need to respond to iron when they send us a new export task to be completed.
return \Queue::marshal();
}
}
我的导出作业类具有以下内容:
<?php
namespace App\Jobs;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Bus\SelfHandling;
use Illuminate\Contracts\Queue\ShouldQueue;
class Export extends Job implements SelfHandling, ShouldQueue
{
use InteractsWithQueue, SerializesModels;
protected $data;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($data)
{
$this->data = $data;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
\Log::info(print_r($this->data, true));
// Code to export a CSV and email the user some
// the URL of where they can access the file.
\Log::info('RUNNING EXPORT CLASS API');
}
}