Skip to content

Commit

Permalink
new producer that loads data from STDIN
Browse files Browse the repository at this point in the history
  • Loading branch information
videlalvaro committed Nov 25, 2011
1 parent 2c04ece commit bf8aaca
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions Command/StdInProducerCommand.php
@@ -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));
}
}

0 comments on commit bf8aaca

Please sign in to comment.