$ composer require fintem/mq-notification-bundle
<?php
// ...
$bundles = [
// ...
new OldSound\RabbitMqBundle\OldSoundRabbitMqBundle(),
new Fintem\MQNotificationBundle\MQNotificationBundle(),
];
// ...
}
Add the old_sound_rabbit_mq section in your configuration file and describe connection. More info here.
mq_notification:
mq_connection_name: default # connection name described under old_sound_rabbit_mq
service_name: your_app_name # custom your application name
<?php
use Fintem\MQNotificationBundle\Event\NotifyEvent;
$notifyOnTerminate = false; // push notification on kernel/console terminate/exception
$event = new NotifyEvent('test_message', ['some' => 'data'], $notifyOnTerminate);
$this->dispatcher->dispatch(NotifyEvent::NAME, $event);
$ app/console rabbitmq:consumer notification
- notification_received
- notification_received.message_name
e.g. notification_received.user_created
<?php
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Fintem\MQNotificationBundle\Event\NotificationReceivedEvent;
class NotificationSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
'notification_received' => ['onNotificationReceived', 0],
'notification_received.user_created' => ['onUserCreated', 0],
];
}
public function onNotificationReceived(NotificationReceivedEvent $event)
{
}
public function onUserCreated(NotificationReceivedEvent $event)
{
// $user = $event->getData();
}
}