Laravel. Common queue for two projects

laravel multiple queues
laravel queue example
laravel queue events
laravel run queue in background
laravel queue multiple workers
laravel queue not working
laravel queue closure
laravel check if queue is running

I have two different projects. Laravel project A and Laravel project B. And I need create task from Project A to project B through queue. And I dont want create Job for this in Project A.

Currently my realisation is:

Project A

Job with state but without business logic:

<?php

namespace App\Jobs;

use ...;

/**
 * Fake class!!!
 */
class MyJob extends Job implements ShouldQueue
{
    use InteractsWithQueue, SerializesModels;

    public $queue = 'MyQueue';

    /**
     * Some state
     */
    protected $_contentId;

    public function __construct($contentId)
    {
        $this->_contentId = $contentId;
    }

    /**
     * Excess. I dont need business logic in project A.
     */
    public function handle()
    {
    }
}

And I push job into queue in Project A:

    ...
    $this->dispatch(
        new MyJob($this->_contentId)
    );
    ...

Project B

<?php

namespace App\Jobs;

use ...;

/**
 * Really needed class
 */
class MyJob extends Job implements ShouldQueue
{
    use InteractsWithQueue, SerializesModels;

    public $queue = 'MyQueue';

    /**
     * Some state
     */
    protected $_contentId;

    public function __construct($contentId)
    {
        $this->_contentId = $contentId;
    }

    /**
     * Here is my business logic. In Project B!
     */
    public function handle()
    {
        Artisan::call('my_command', [
            'id' => $this->_contentId,
        ]);
    }
}

So, how to do without MyJob in Project A?

if you connect both laravels apps to a same queue server. you can put jobs on the other site queue. For example, if you are in Laravel A

$job = (new Job())->onQueue('theQueueForLaravelB')
dispatch($job);

But to complete this, you should make a basic job that dispach a new one with parameter data. Like:

class DispatchNewJob implements ShouldQueue
{
    use InteractsWithQueue, Queueable, SerializesModels;

    private $class_to_create;
    private $data;

    public function __construct($class_to_create, $data)
    {
        $this->class_to_create = $class_to_create;
        $this->data = $data;
    }

    public function handle()
    {
        dispatch(new $this->class_to_create($this->data));
    }
}

So, you can now dispatch any job from laravel A, to laravel B with any data.

You can call

$job = (new DispatchNewJob('App\Jobs\JobInLaravelB', ['data'=>'myawesomedata'])
               ->onQueue('LaravelBQueue');
dispatch($job);

Sorry for my english, i'm from Argentina.

Queues Redis two projects on one server, on CentOS server I have two projects, projects don't have databases, queues there https://laracasts.com/discuss/channels/laravel/using-redis-for-queues-for� The queue:work Artisan command exposes a --timeout option. The --timeout option specifies how long the Laravel queue master process will wait before killing off a child queue worker that is processing a job. Sometimes a child queue process can become "frozen" for various reasons.

Laravel expects both ends (dispatcher and listener) to run the same application - so that serializations and deserializations work correctly.

Out of box, Laravel (or Lumen) doesn't support plain queue messages so that receiving end may run a different application or framework.

If you use SQS for queues, my custom SQS connector can help you. Otherwise, you would have to write one yourself.

Running Multiple Queue Workers, All Threads � Popular This Week � Popular All Time � Solved � Unsolved I've used the numprocs option in supervisor to run multiple queue workers. on the project before told me that running queue:listen was duplicating the Looks like the current Redis queue laravel implementation does not provides� For instance, laravel new blog will create a directory named blog containing a fresh Laravel installation with all of Laravel's dependencies already installed: laravel new blog Via Composer Create-Project. Alternatively, you may also install Laravel by issuing the Composer create-project command in your terminal:

How about this (it's a total hack though), create a composer project that contains a bunch of Job classes and a bunch of job-handler classes, for example:

<?php

namespace Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

class JobType1 implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        JobType1Handler::handle();
    }
}

class JobType1Handler
{
    public static function handle()
    {

    }
}

and then modify the handler code in your Project B . So you would be modifying the source in your /vendors folder, which would make deployment difficult.

Running queues for multiple applications on the same server with , Running multiple queues on the same server using Laravel horizon user will be 'forge' and the directory should be the root of your project. How To Pay Off Your Mortgage Fast Using Velocity Banking | How To Pay Off Your Mortgage In 5-7 Years - Duration: 41:34. Think Wealthy with Mike Adams Recommended for you

@Kolovious Answer is the correct one, only two notes:

  1. DispatchNewJob should exists on both Laravel A & B
  2. There's a typo, it should be $this->class_to_create and not $this->$class_to_create

Queues - Laravel, However, any given queue connection may have multiple "queues" which may be thought of as different stacks or piles of queued jobs. Note that each� In this post, we will discuss Laravel Queues which is one of the best features of the Laravel framework. So let’s dive in. Laravel Queues. Laravel Queues provide integration of a variety of different queue backends like Beanstalkd, Amazon SQS, Redis, synchronous (sync) and database. You can find the queue configurations in the config/queue

Laravel Jobs and Queue 101: queue connections, using multiple , of Laravel. Consider upgrading your project to Laravel 7.x. To push a new job onto the queue, use the Queue::push method: The second argument is an array of data that should be passed to the handler. Laravel attempts to take the pain out of development by easing common tasks used in most web projects. Laravel Forge. Instant PHP Platforms on DigitalOcean, Linode, and more. Featuring push-to-deploy, Redis, queues, and everything else you could need to launch and deploy impressive Laravel applications.

Make your product ready to scale using Laravel Queues — from the , Consider upgrading your project to Laravel 7.x. The queue configuration file is stored in config/queue.php . If you are working with multiple queue connections , you may specify which connection to push a job to. Laravel attempts to take the pain out of development by easing common tasks used in most web projects. Laravel 2019, the complete guide with real world projects 4.5 (1,871 ratings) Course Ratings are calculated from individual students’ ratings and a variety of other signals, like age of rating and reliability, to ensure that they reflect course quality fairly and accurately.

Consider upgrading your project to Laravel 7.x. The queue configuration file is stored in config/queue.php . Passing The Same Payload To Multiple Jobs the pain out of development by easing common tasks used in most web projects. Laravel is one of the most popular frameworks for developing web applications. It offers a simple and fast development environment for developers. Laravel aims to take the tedium out of routine web projects like authentication, routing, sessions and caching, making the development process simple and straightforward.

Comments
  • Hello to Argentina from Russia :) Thanks for answer. Currently I use this approach.
  • @Kolovious me podrías dar una mano en algo similar que estoy haciendo?
  • @JuanPabloB escribime por privado y lo vemos
  • @Kolovious entro a tu perfil y no puedo enviar mensaje privado, no encuentro!