-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
No class "Key" in Lock/DeduplicateStamp #60510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Installing symfony/lock sets the .env var to flock
but that should be enough to serialize, right? symfony new --webapp lock-bug --version=next && cd lock-bug
echo "DATABASE_URL=sqlite:///%kernel.project_dir%/var/data.db" > .env.local
composer req symfony/lock
mkdir src/Message -p
cat > src/Message/TestMessage.php <<'END'
<?php
namespace App\Message;
use Symfony\Component\Messenger\Attribute\AsMessage;
#[AsMessage('async')]
final class TestMessage
{
}
END
mkdir -p src/Command
cat > src/Command/DispatchCommand.php <<'END'
<?php
namespace App\Command;
use App\Message\TestMessage;
use Symfony\Component\Console\Attribute\Argument;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Attribute\Option;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Messenger\Stamp\DeduplicateStamp;
#[AsCommand('app:dispatch', 'Dispatch with a dedup stamp')]
class DispatchCommand
{
public function __construct(
private readonly MessageBusInterface $messageBus,
)
{
}
public function __invoke(SymfonyStyle $io): int
{
$this->messageBus->dispatch(new TestMessage(), [
new DeduplicateStamp('the-lock-resource')
]);
return Command::SUCCESS;
}
}
END
bin/console cache:clear
bin/console app:dispatch It occurs to me that the string 'the-lock-resource' might be a class and not a key to a class, like the cache component. I've never used the lock component before, so I was just using the example in the blog post at https://symfony.com/blog/new-in-symfony-7-3-messenger-improvements Probably the real solution is to call it correctly. Still, a message about installing symfony/lock would be helpful. |
I think we can increase DX by requiring the key to be passed as a |
@xabbuh not sure we should do that. If you reuse the same Key object to dispatch multiple messages, the 2 stamps will be considered identical rather than being duplicates (as they share the same Key). What we should do instead is check for the class existing in the constructor and throw a meaningful exception. |
@stof got it, PR updated |
Symfony version(s) affected
7.3.0-BETA2
Description
symfony/lock is not required in messenger, so if you use it you get an error.
How to reproduce
Install messenger and try to use the DeduplicateStamp stamp
Possible Solution
Probably check that the class exists and if not prompt with a note to run
Additional Context
No response
The text was updated successfully, but these errors were encountered: