Skip to content

Commit

Permalink
Merge pull request php-amqplib#236 from jaymecd/producer_extend
Browse files Browse the repository at this point in the history
Support for route and format for StdInProducer
  • Loading branch information
videlalvaro committed Jan 28, 2015
2 parents b78ac22 + 06f48b7 commit a15a4eb
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions Command/StdInProducerCommand.php
Expand Up @@ -9,14 +9,18 @@

class StdInProducerCommand extends BaseRabbitMqCommand
{

const FORMAT_PHP = 'php';
const FORMAT_RAW = 'raw';

protected function configure()
{
parent::configure();

$this
->setName('rabbitmq:stdin-producer')
->addArgument('name', InputArgument::REQUIRED, 'Producer Name')
->addOption('route', 'r', InputOption::VALUE_OPTIONAL, 'Routing Key', '')
->addOption('format', 'f', InputOption::VALUE_OPTIONAL, 'Payload Format', self::FORMAT_PHP)
->addOption('debug', 'd', InputOption::VALUE_OPTIONAL, 'Enable Debugging', false)
;
}
Expand All @@ -39,7 +43,21 @@ protected function execute(InputInterface $input, OutputInterface $output)
while (!feof(STDIN)) {
$data .= fread(STDIN, 8192);
}

$route = $input->getOption('route');
$format = $input->getOption('format');

switch ($format) {
case self::FORMAT_RAW:
break; // data as is
case self::FORMAT_PHP:
$data = serialize($data);
break;
default:
throw new \InvalidArgumentException(sprintf('Invalid payload format "%s", expecting one of: %s.',
$format, implode(', ', [self::FORMAT_PHP, self::FORMAT_RAW])));
}

$producer->publish(serialize($data));
$producer->publish($data, $route);
}
}

0 comments on commit a15a4eb

Please sign in to comment.