【问题标题】:Controlling the tubes for Queued Events in Laravel 5在 Laravel 5 中控制队列事件的管道
【发布时间】:2015-05-15 11:54:09
【问题描述】:

所以我开始在 L5 中使用排队事件来处理一些逻辑,我想知道是否可以告诉 laravel 在将事件推送到 Beanstalkd 时使用什么管。

我在文档中看不到任何关于它的内容。

【问题讨论】:

    标签: laravel laravel-5 beanstalkd


    【解决方案1】:

    在挖掘Event Dispatcher code之后。

    我发现如果你的事件处理程序上有队列方法,laravel 会将参数传递给该方法,并让你手动调用 push 方法。

    因此,如果您有 SendEmail 事件处理程序,您可以执行以下操作:

    <?php namespace App\Handlers\Events;
    
    use App\Events\UserWasCreated;
    
    use Illuminate\Queue\InteractsWithQueue;
    use Illuminate\Contracts\Queue\ShouldBeQueued;
    
    class SendEmail implements ShouldBeQueued {
        use InteractsWithQueue;
    
        public function __construct()
        {
        }
    
        public function queue($queue, $job, $args)
        {
            // Manually call push
            $queue->push($job, $args, 'TubeNameHere');
            // Or pushOn
            $queue->pushOn('TubeNameHere', $job, $args);
        }
    
        public function handle(UserWasCreated $event)
        {
            // Handle the event here
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-22
      • 2016-12-08
      • 1970-01-01
      相关资源
      最近更新 更多