How to retrieve queue from aws SQS using laravel - laravel

I am connecting AWS SQS FIFO Queue in Laravel , I want to retrieve queue from AWS SQS with Laravel.
Here is my env file
QUEUE_CONNECTION=sqs
AWS_ACCESS_KEY_ID=RRKKKAKIAWY7CM4EBHHHH
AWS_SECRET_ACCESS_KEY=qN25sCiUvrArRdtF+HWbL6zdXFK6lo5SR563
AWS_DEFAULT_REGION=eu-west-1
SQS_PREFIX=https://sqs.eu-west-1.amazonaws.com/465941881099
SQS_QUEUE=NewTestNotificationQueue
AWS_BUCKET=
I installed composer require aws/aws-sdk-php
and using Laravel Framework 7.30.4
But while executing php artisan queue:listen I am getting error as
follows
[2021-10-06 12:23:09][47e7f3ca-12cf-4f83-b2c3-0dd6942f156e]
Processing:
[2021-10-06 12:23:09][47e7f3ca-12cf-4f83-b2c3-0dd6942f156e]
Failed:
Can you help ....
my job class
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class listenSQS implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable,
SerializesModels;
/**
* Create a new job instance.
*
* #return void
*/
public function __construct()
{
//
}
/**
* Execute the job.
*
* #return void
*/
public function handle()
{
}
}
Can you please help the above is my job class

Related

BroadcastOn function not work in laravel event broadcast?

I used pusher for my project. I configure broadcasting as per laravel docs. When I fired my event pusher does not work for me. But when I send data from pusher console then pusher receive this data. I also try vinkla/pusher. Its work fine but laravel event broadcasting not work. It's not broadcast my messages. Please help me.
Here is my Event
<?php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class ChatNotification implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $message;
/**
* Create a new event instance.
*
* #return void
*/
public function __construct($message)
{
$this->message=$message;
}
/**
* Get the channels the event should broadcast on.
*
* #return Channel|array
*/
public function broadcastOn()
{
dd($this->message);
$GroupId=$this->message->fk_group_id;
if(!empty($GroupId) && !is_null($GroupId)){
return new PresenceChannel('Room.'.$GroupId);
}else{
return new PrivateChannel('Chat.'.$this->message->to_id);
}
}
}

Laravel 6 - dispatch event doesn't work (broadcast drive log)

I am trying to start the work on broadcasting and event, but so far the event won't fire at all, and I don't have a clue what is going on
In my .env file I have this:
BROADCAST_DRIVER=log
Event class:
<?php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class OrdersStatusUpdate implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* Create a new event instance.
*
* #return void
*/
public function __construct()
{
}
/**
* Get the channels the event should broadcast on.
*
* #return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new Channel('orders');
// return new PrivateChannel('channel-name');
}
}
My controller:
<?php
namespace App\Http\Controllers\Frontend;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Events\OrdersStatusUpdate;
class SiteController extends Controller
{
public function index(){
OrdersStatusUpdate::dispatch();
}
}
Nothing is happening when I fire a request in the browser (log is not created).
I am running PHP 7.4.3 on localhost:9099
What am I doing wrong here?
Try to run php artisan queue:work to start your queue worker and processing queue jobs. You can also use supervisor to automate this.

How to push the Laravel job to the queue

I have a class XYJob which was created by artisan command and implements the ShouldQueue class.
The QUEUE_DRIVER=redis in the .env file.
The problem is that when i dispatch the job, it runs as a simple php function. The queue listener is not running, but the job runs as a simple function.
It is laravel 5.8 application with predis/predis: ^1.1.
I have tried to clear the cache and the config. I have tried to use composer dump-autoload.
namespace Modules\ModuleName\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class XYJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* #return void
*/
public function __construct()
{
//
}
/**
* Execute the job.
*
* #return void
*/
public function handle()
{
\Log::info('Job is running');
}
}
Laravel documentation says:
The generated class will implement the ShouldQueue interface, indicating to Laravel that the job should be pushed onto the queue to run asynchronously.
BUT my job is definitely running.
Laravel 5.8 application should has QUEUE_CONNECTION in the .env file.
How are you dispatching the job? Have you followed the example on the Laravel doscs site at https://laravel.com/docs/5.8/queues#dispatching-jobs i.e.
\App\Jobs\ProcessPodcast::dispatch($podcast);
or dispatch(new \App\Jobs\ProcessPodcast($podcast);
dispatch(new \App\Jobs\ProcessPodcast($podcast);
If the job is not dispatched in this manner (i.e. you're simply newing up the job class), it will not be pushed to the queue.

error in registering command in laravel 5.0

i am trying to make my own command in laravel 5.0, but it generates the following error. i have registerd my command in kernel. following are my codes
//folowing error
[ErrorException]
Argument 1 passed to Illuminate\Console\Application::add() must be an instance of Symfony\Component\Console\Command
\Command, instance of App\console\Commands\qwork given, called in C:\xampp\htdocs\queue_mail\vendor\laravel\framewo
rk\src\Illuminate\Console\Application.php on line 115 and defined
//my command qwork.php
<?php namespace App\console\Commands;
use DB;
use App\Commands\Command;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Bus\SelfHandling;
use Illuminate\Contracts\Queue\ShouldBeQueued;
class qwork extends Command implements SelfHandling, ShouldBeQueued {
use InteractsWithQueue, SerializesModels;
/**
* Create a new command instance.
*
* #return void
*/
public function __construct()
{
//
}
/**
* Execute the command.
*
* #return void
*/
public function handle()
{
DB::insert('insert into users (name, email) values (?, ?)', ['faran', 'ran.rana#gmail.com']);
}
}
//then defining route by:
Route::get('/run', function()
{
Artisan::queue('command:qwork');
});
Replace
use App\Commands\Command;
with
use Illuminate\Console\Command;

Laravel Queue is Processed but email not found in inbox

I Am sending emails in Laravel Queue. While using the send method, as shown here
Mail::to($userSocial->getEmail())->send(new WelcomeEmail('1234567', "haha", "Makamu"));
my email is delivered to my inbox. However when i switch to queue like below
Mail::to($userSocial->getEmail())->queue(new WelcomeEmail('1234567', "haha", "Makamu"));
I also used this method
SendEmailSocialReg::dispatch('12345678', "haha", "Makamu");
and monitor via queue:listen i am get the processing. then processed message. No error however.
What could be wrong?
my WelcomeEmail
<?php
namespace App\Mail;
use App\User;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class WelcomeEmail extends Mailable
{
use Queueable, SerializesModels;
public $password;
public $client_name;
public $client_email;
/**
* Create a new message instance.
*
* #return void
*/
public function __construct($password, $email, $name)
{
$this->password = $password;
$this->client_name = $name;
$this->client_email = $email;
}
/**
* Build the message.
*
* #return $this
*/
public function build()
{
return $this->view('email.auto');
}
}
Your WelcomeEmail class must return markdown() at build() function like this:
/**
* Build the message.
*
* #return $this
*/
public function build()
{
return $this->markdown('email.auto');
}
Then the queue worker must be executed with this command:
php artisan queue:work --queue=default

Resources