Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JusteLeblanc/33a877e5e0d49e8a38e5d7a9adf30338 to your computer and use it in GitHub Desktop.
Save JusteLeblanc/33a877e5e0d49e8a38e5d7a9adf30338 to your computer and use it in GitHub Desktop.
Elements to configure RabbitMQ
### Installation of rabbitmq-cli-consumer
To read before the installation: https://github.com/corvus-ch/rabbitmq-cli-consumer
On the server install rabbitmq-cli-consumer
mkdir -p rabbitmq-cli-consumer
cd rabbitmq-cli-consumer/ && wget https://github.com/corvus-ch/rabbitmq-cli-consumer/releases/download/2.2.0/rabbitmq-cli-consumer_2.2.0_linux_amd64.tar.gz
tar xfzv rabbitmq-cli-consumer_2.2.0_linux_amd64.tar.gz
sudo mv rabbitmq-cli-consumer /usr/local/bin/
rm *
Run rabbitmq-cli-consumer specifying the command you've just created
rabbitmq-cli-consumer -V -u "amqp://dev:dev@localhost" -e "symfony/bin/console <YOUR_CONSUMER_COMMAND>" -q <YOUR_PRODUCER_NAME>
Access to RabbitMQAdmin interface to check if messages are well-processed
...
old_sound_rabbit_mq:
connections:
default:
host: '%rabbitmq_host%'
user: '%rabbitmq_user%'
password: '%rabbitmq_password%'
vhost: '%rabbitmq_vhost%'
producers:
<PRODUCER_NAME>:
connection: default
exchange_options:
name: <PRODUCER_NAME>
type: direct
queue_options:
name: <PRODUCER_NAME>
<?php
class NewController extends Controller
{
public function indexAction(Request $request)
{
...
$this->get('old_sound_rabbit_mq.<PRODUCER_NAME>_producer')->publish(<UNIQ_MESSAGE_ID>);
}
}
<?php
namespace App\Command;
use AssuranceVieBundle\Entity\Subscription;
use AssuranceVieBundle\Generator\PdfGenerator;
use AssuranceVieBundle\Manager\SubscriptionManager;
use AssuranceVieBundle\Service\Mailer;
use Doctrine\ORM\EntityRepository;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Class YourConsumerCommand
*/
class YourConsumerCommand extends ContainerAwareCommand
{
/**
*
*/
protected function configure()
{
$this
->setName('<YOUR_CONSUMER_COMMAND_NAME>')
->addArgument('event', InputArgument::REQUIRED);
}
/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|null|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
...
try {
...
} catch (\Exception $e) {
$logger = $this->getContainer()->get('logger');
$logger->error($e->getMessage());
...
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment