php bin/console messenger:consume -vv scheduler_default
In ConsumeMessagesCommand.php line 168:
[Symfony\Component\Console\Exception\RuntimeException]
The receiver "scheduler_default" does not exist.
I have followed the steps to create a scheduler and consume messages as schedules, my scheduler is not being identified as a scheduler even though I have used the correct Attribute and have implemented the ScheduleProviderInterface.
Following this official documentaion, according to this I have to consume message as scheduler_ followed by the AsSchedule attribute name. But it says the receiver does not exist.
Php bin/console debug:scheduler says "No schedules found"
Scheduler
=========
[ERROR] No schedules found.
Here is my Schedule.php file
// src/Scheduler/Schedule.php
namespace App\Scheduler;
use Symfony\Component\Scheduler\RecurringMessage;
use Symfony\Component\Scheduler\Schedule;
use Symfony\Component\Scheduler\ScheduleProviderInterface;
use App\Message\Foo;
#[AsSchedule('default')]
class DefaultScheduleProvider implements ScheduleProviderInterface
{
public function getSchedule(): Schedule
{
$schedule = new Schedule();
$schedule->add(RecurringMessage::every('2 days', new Foo()));
return $schedule;
}
}
Config packages/messenger.yaml
framework:
messenger:
# Uncomment this (and the failed transport below) to send failed messages to this transport for later handling.
# failure_transport: failed
transports:
# https://symfony.com/doc/current/messenger.html#transport-configuration
# async: '%env(MESSENGER_TRANSPORT_DSN)%'
# failed: 'doctrine://default?queue_name=failed'
# sync: 'sync://'
routing:
# Route your messages to the transports
# 'App\Message\YourMessage': async
I'm not sure where its going wrong, I just want to set a basic scheduler for doing tasks periodically.
The attribute #[AsSchedule] needs be imported, since it didn't throw any error during compilation, it went undetected.
use Symfony\Component\Scheduler\Attribute\AsSchedule;
Importing the class, solved the problem.