Skip to content

Commit 06f48b7

Browse files
committed
Support for route and payload format
1 parent b78ac22 commit 06f48b7

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

Command/StdInProducerCommand.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@
99

1010
class StdInProducerCommand extends BaseRabbitMqCommand
1111
{
12-
12+
const FORMAT_PHP = 'php';
13+
const FORMAT_RAW = 'raw';
14+
1315
protected function configure()
1416
{
1517
parent::configure();
1618

1719
$this
1820
->setName('rabbitmq:stdin-producer')
1921
->addArgument('name', InputArgument::REQUIRED, 'Producer Name')
22+
->addOption('route', 'r', InputOption::VALUE_OPTIONAL, 'Routing Key', '')
23+
->addOption('format', 'f', InputOption::VALUE_OPTIONAL, 'Payload Format', self::FORMAT_PHP)
2024
->addOption('debug', 'd', InputOption::VALUE_OPTIONAL, 'Enable Debugging', false)
2125
;
2226
}
@@ -39,7 +43,21 @@ protected function execute(InputInterface $input, OutputInterface $output)
3943
while (!feof(STDIN)) {
4044
$data .= fread(STDIN, 8192);
4145
}
46+
47+
$route = $input->getOption('route');
48+
$format = $input->getOption('format');
49+
50+
switch ($format) {
51+
case self::FORMAT_RAW:
52+
break; // data as is
53+
case self::FORMAT_PHP:
54+
$data = serialize($data);
55+
break;
56+
default:
57+
throw new \InvalidArgumentException(sprintf('Invalid payload format "%s", expecting one of: %s.',
58+
$format, implode(', ', [self::FORMAT_PHP, self::FORMAT_RAW])));
59+
}
4260

43-
$producer->publish(serialize($data));
61+
$producer->publish($data, $route);
4462
}
4563
}

0 commit comments

Comments
 (0)