![](/img/trans.png)
[英]trigger queue jobs without waiting sending email in Laravel v4.2
[英]How to use two or more queue driver in one project laravel v4.2
我正在laravel v4.2項目中工作,我有不同的隊列任務要執行。 但是現在我想通過使用兩個或多個驅動程序來執行此任務。 例如,我有一個隊列發送注冊電子郵件,現在我想使用Redis服務器發送電子郵件。
我要使用的第二個隊列是向我要使用數據庫驅動器的用戶發送推送通知。 因此有可能在一個項目上使用兩個或多個隊列驅動程序。
請教育我。
謝謝
只需編寫另一個QueueManager
從Base QueueManager
對其進行擴展
擴展您的基本隊列驅動程序
use Illuminate\Queue\Connectors\RedisConnector;
use Illuminate\Queue\QueueManager;
class RedisQueueManager extends QueueManager
{
public function __construct(\Illuminate\Foundation\Application $app)
{
parent::__construct($app);
$this->registerRedisConnector();
}
/**
* Get the name of the default queue connection.
*
* @return string
*/
public function getDefaultDriver()
{
return 'redis';
}
protected function registerRedisConnector()
{
$app = $this->app;
$this->addConnector('redis', function () use ($app) {
return new RedisConnector($app['redis']);
});
}
}
現在創建一個服務提供商以通過應用程序訪問它
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App\Extensions\RedisQueueManager;
class RedisQueueServiceProvider extends ServiceProvider
{
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->bindShared('redis-queue', function ($app) {
return new RedisQueueManager($app);
});
}
}
最后,在config/app.php
provider數組中注冊您的Service提供商。
並使用它。
Route::get('/', function () {
$default = app('queue');
$redis = app('redis-queue');
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.