forked from php-amqplib/RabbitMqBundle
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new producer that loads data from STDIN
- Loading branch information
1 parent
2c04ece
commit bf8aaca
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace OldSound\RabbitMqBundle\Command; | ||
|
||
use Symfony\Component\Console\Input\InputDefinition; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class StdInProducerCommand extends BaseRabbitMqCommand | ||
{ | ||
|
||
protected function configure() | ||
{ | ||
parent::configure(); | ||
|
||
$this | ||
->setName('rabbitmq:stdin-producer') | ||
->addArgument('name', InputArgument::REQUIRED, 'Producer Name') | ||
->addOption('debug', 'd', InputOption::VALUE_OPTIONAL, 'Enable Debugging', false) | ||
; | ||
} | ||
|
||
/** | ||
* Executes the current command. | ||
* | ||
* @param InputInterface $input An InputInterface instance | ||
* @param OutputInterface $output An OutputInterface instance | ||
* | ||
* @return integer 0 if everything went fine, or an error code | ||
* | ||
* @throws \LogicException When this abstract class is not implemented | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
define('AMQP_DEBUG', (bool) $input->getOption('debug')); | ||
|
||
$producer = $this->getContainer()->get(sprintf('old_sound_rabbit_mq.%s_producer', $input->getArgument('name'))); | ||
|
||
$data = ''; | ||
while (!feof(STDIN)) { | ||
$data .= fread(STDIN, 8192); | ||
} | ||
|
||
$producer->publish(serialize($data)); | ||
} | ||
} |