Open hanachan1026 opened 2 years ago
I think you would have to create a new queue connection in config/queue.php
(per Laravel's documentation).
And then:
worker
functionworker.php
file and change the queue connection and queue name used in there (I mean these lines: https://github.com/brefphp/laravel-bridge/blob/36111f777e78759c2f20e9555dea2cd92e606916/worker.php#L19-L20)@mnapoli Could you tell why this implementation does not work?
I'm dynamically getting the queue name through the event variable. It doesn't show any error, but also the message is not sent to the queue.
# File: worker.php
return function (array $event, Context $context) {
/** @var Application $app */
$app = require __DIR__ . '/bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
$kernel->bootstrap();
$message = $event['Records'][0];
$queueName = explode(':', $message['eventSourceARN'])[5];
$queueUrl = getenv('SQS_PREFIX') . $queueName;
Log::info("Message '{$message['messageId']}' sent to '{$queueUrl}' ");
return $app->makeWith(LaravelSqsHandler::class, [
'connection' => 'sqs',
'queue' => $queueUrl,
]);
};
References:
Would you help me? Thanks
Did you figure this out?
I haven't tested this but you should be able to put an environment variable per handler.
constructs:
primary-queue:
type: queue
worker:
handler: Bref\LaravelBridge\Queue\QueueHandler
runtime: php-81
timeout: 60 # seconds
environment:
QUEUE_HANDLE_CONNECTION: primary
secondary-queue:
type: queue
worker:
handler: Bref\LaravelBridge\Queue\QueueHandler
runtime: php-81
timeout: 60 # seconds
environment:
QUEUE_HANDLE_CONNECTION: secondary
Then override your the existing service provider definition of $connection, in your own AppServiceProvider.
$this->app->when(QueueHandler::class)
->needs('$connection')
->give(env('QUEUE_HANDLE_CONNECTION'));
Ideally this would all be magically resolved by QueueHandler instead based on the Job Queue ARN itself. I'll see if I can put together a PR later.
When I setup single queue, it works like a charm. But if I want to have multiple queues, since we can only specify one queue url in
SQS_QUEUE
I don't know how to setup.The reason why I want multiple queues in 1 application is that I want to know if a specific job is still processing. To do that I separate queues for each jobs and long polling the status of queue.