-
Notifications
You must be signed in to change notification settings - Fork 439
/
Copy pathProduceMessageCommand.php
55 lines (46 loc) · 1.34 KB
/
ProduceMessageCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
namespace Enqueue\Symfony\Client;
use Enqueue\Client\ProducerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class ProduceMessageCommand extends Command
{
protected static $defaultName = 'enqueue:produce';
/**
* @var ProducerInterface
*/
private $producer;
/**
* @param ProducerInterface $producer
*/
public function __construct(ProducerInterface $producer)
{
parent::__construct(static::$defaultName);
$this->producer = $producer;
}
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setAliases(['enq:p'])
->setDescription('A command to send a message to topic')
->addArgument('topic', InputArgument::REQUIRED, 'A topic to send message to')
->addArgument('message', InputArgument::REQUIRED, 'A message to send')
;
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->producer->sendEvent(
$input->getArgument('topic'),
$input->getArgument('message')
);
$output->writeln('Message is sent');
}
}