/**
  * {@inheritdoc}
  */
 public function dispatch(RequestInterface $request, ResponseInterface $response = null)
 {
     parent::dispatch($request, $response);
     /* @var $request \Zend\Console\Request */
     /* @var $response \Zend\Console\Response */
     $console = $this->getConsole();
     $console->writeLine('Setting up the AMQP fabric');
     $config = $this->getConfig();
     if (empty($config['exchanges'])) {
         $console->writeLine('No exchanges found to configure', ColorInterface::RED);
         $response->setErrorLevel(1);
         return;
     }
     if (empty($config['queues'])) {
         $console->writeLine('No queues found to configure', ColorInterface::RED);
         $response->setErrorLevel(1);
         return;
     }
     $console->write('Declaring exchanges ...' . PHP_EOL);
     $exchangeFactory = $this->getExchangeFactory();
     foreach ($config['exchanges'] as $name => $spec) {
         $channel = $this->createChannel($spec, $config['default_connection']);
         $spec = new ExchangeSpecification($spec);
         $exchangeFactory->create($spec, $channel, true);
     }
     $console->write('Declaring queues ...' . PHP_EOL);
     $queueFactory = $this->getQueueFactory();
     foreach ($config['queues'] as $name => $spec) {
         $channel = $this->createChannel($spec, $config['default_connection']);
         $spec = new QueueSpecification($spec);
         $queueFactory->create($spec, $channel, true);
     }
     $console->writeLine('DONE', ColorInterface::GREEN);
 }
 /**
  * {@inheritdoc}
  */
 public function dispatch(RequestInterface $request, ResponseInterface $response = null)
 {
     parent::dispatch($request, $response);
     /* @var $request \Zend\Console\Request */
     /* @var $response \Zend\Console\Response */
     $producerName = $request->getParam('name');
     $producerManager = $this->getProducerManager();
     if (!$producerManager->has($producerName)) {
         $this->getConsole()->writeLine('ERROR: Producer "' . $producerName . '" not found', ColorInterface::RED);
         $response->setErrorLevel(1);
         return;
     }
     $producer = $producerManager->get($producerName);
     $route = $request->getParam('route', '');
     $msg = trim($request->getParam('msg'));
     $producer->publish($msg, $route);
 }
 /**
  * {@inheritdoc}
  */
 public function dispatch(RequestInterface $request, ResponseInterface $response = null)
 {
     parent::dispatch($request, $response);
     /* @var $request \Zend\Console\Request */
     /* @var $response \Zend\Console\Response */
     $consumerName = $request->getParam('consumer-name');
     $consumerManager = $this->getConsumerManager();
     if (!$consumerManager->has($consumerName)) {
         $this->getConsole()->writeLine('ERROR: Consumer "' . $consumerName . '" not found', ColorInterface::RED);
         $response->setErrorLevel(1);
         return;
     }
     $confirm = new Prompt\Confirm('Are you sure you want to purge? [y/n]', 'y', 'n');
     $confirm->setConsole($this->getConsole());
     if ($request->getParam('no-confirmation', false) || $confirm->show()) {
         $consumer = $consumerManager->get($consumerName);
         $consumer->purge();
         $this->getConsole()->writeLine('OK', ColorInterface::GREEN);
     } else {
         $this->getConsole()->writeLine('Purging cancelled!', ColorInterface::YELLOW);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function dispatch(RequestInterface $request, ResponseInterface $response = null)
 {
     parent::dispatch($request, $response);
     /* @var $request \Zend\Console\Request */
     /* @var $response \Zend\Console\Response */
     $type = $request->getParam('type');
     $config = $this->getServiceLocator()->get('Config');
     $moduleConfig = $config['humus_amqp_module'];
     $this->getConsole()->writeLine('List of all available ' . $type, ColorInterface::GREEN);
     $cType = str_replace('-', '_', $type);
     if (!isset($moduleConfig[$cType])) {
         $this->getConsole()->writeLine('No ' . $type . ' found', ColorInterface::RED);
         return;
     }
     $list = array_keys($moduleConfig[str_replace('-', '_', $type)]);
     if (0 == count($list)) {
         $this->getConsole()->writeLine('No ' . $type . ' found', ColorInterface::RED);
     }
     foreach ($list as $entry) {
         $this->getConsole()->writeLine($entry);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function dispatch(RequestInterface $request, ResponseInterface $response = null)
 {
     parent::dispatch($request, $response);
     /* @var $request \Zend\Console\Request */
     /* @var $response \Zend\Console\Response */
     if (!$request->getParam('without-signals') && !$request->getParam('w')) {
         $this->registerSignalHandler();
     }
     $rpcServerName = $request->getParam('name');
     if (!$this->getRpcServerManager()->has($rpcServerName)) {
         $this->getConsole()->writeLine('ERROR: RPC-Server "' . $rpcServerName . '" not found', ColorInterface::RED);
         $response->setErrorLevel(1);
         return;
     }
     $amount = $request->getParam('amount', 0);
     if (!is_numeric($amount)) {
         $this->getConsole()->writeLine('Error: Expected integer for amount', ColorInterface::RED);
         $response->setErrorLevel(1);
         return;
     } else {
         $this->rpcServer = $this->getRpcServerManager()->get($rpcServerName);
         $this->rpcServer->consume($amount);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function dispatch(RequestInterface $request, ResponseInterface $response = null)
 {
     parent::dispatch($request, $response);
     /* @var $request \Zend\Console\Request */
     /* @var $response \Zend\Console\Response */
     if (!$request->getParam('without-signals') && !$request->getParam('w')) {
         $this->registerSignalHandler();
     }
     $cm = $this->getConsumerManager();
     $name = $request->getParam('name');
     if (!$cm->has($name)) {
         $this->getConsole()->writeLine('Error: unknown consumer "' . $name . '"', ColorInterface::RED);
         $response->setErrorLevel(1);
         return;
     }
     $this->consumer = $cm->get($request->getParam('name'));
     $amount = $request->getParam('amount', 0);
     if (!is_numeric($amount)) {
         $this->getConsole()->writeLine('Error: amount should be null or greater than 0', ColorInterface::RED);
         $response->setErrorLevel(1);
         return;
     }
     $this->consumer->consume($amount);
 }
 /**
  * {@inheritdoc}
  */
 public function dispatch(RequestInterface $request, ResponseInterface $response = null)
 {
     parent::dispatch($request, $response);
     /* @var $response \Zend\Console\Response */
     $config = $this->getServiceLocator()->get('Config');
     $moduleConfig = $config['humus_amqp_module'];
     $exchanges = array();
     foreach ($moduleConfig['exchanges'] as $name => $options) {
         $spec = new ExchangeSpecification($options);
         $exchanges[$spec->getType()][] = $name;
     }
     if (empty($exchanges)) {
         $this->getConsole()->writeLine('No exchanges found', ColorInterface::RED);
         $response->setErrorLevel(1);
         return;
     }
     $this->getConsole()->writeLine('List of all exchanges', ColorInterface::GREEN);
     foreach ($exchanges as $type => $values) {
         $this->getConsole()->writeLine('Exchange-Type: ' . $type, ColorInterface::GREEN);
         foreach (array_unique($values) as $value) {
             $this->getConsole()->writeLine($value);
         }
     }
 }