LogRabbitMq
, (*1)
Installation
composer require xervice/log-rabbitmq
Configuration
To use rabbitmq as log provider, you have to define it in the LoggerDependencyProvider and RabbitMQDepoendencyProvider., (*2)
<?php
namespace App\Logger;
use Xervice\Logger\LoggerDependencyProvider as XerviceLoggerDependencyProvider;
use Xervice\LogRabbitMq\Business\Log\QueueLogHandler;
class LoggerDependencyProvider extends XerviceLoggerDependencyProvider
{
/**
* @return array
*/
protected function getLogHandler(): array
{
return [
new QueueLogHandler()
];
}
}
<?php
namespace App\RabbitMQ;
use Xervice\LogRabbitMq\Business\Queue\LogExchange;
use Xervice\LogRabbitMq\Business\Queue\LogQueue;
use Xervice\RabbitMQ\RabbitMQDependencyProvider as XerviceRabbitMQDependencyProvider;
use XerviceTest\LogRabbitMq\Listener\LogListener;
class RabbitMQDependencyProvider extends XerviceRabbitMQDependencyProvider
{
/**
* @return array
*/
protected function getQueues(): array
{
return [
new LogQueue()
];
}
/**
* @return array
*/
protected function getExchanges(): array
{
return [
new LogExchange()
];
}
}
To add LogHandler as Worker you can extend from \Xervice\LogRabbitMq\Business\Queue\AbstractLogQueueListener., (*3)
Example, (*4)
<?php
namespace XerviceTest\LogRabbitMq\Listener;
use DataProvider\LogMessageDataProvider;
use Xervice\LogRabbitMq\Business\Queue\AbstractLogQueueListener;
class LogListener extends AbstractLogQueueListener
{
/**
* @param \DataProvider\LogMessageDataProvider $dataProvider
*/
public function handleLog(LogMessageDataProvider $dataProvider)
{
echo $dataProvider->getTitle();
}
}
Adding to RabbitMQDependencyProvider, (*5)
<?php
namespace App\RabbitMQ;
use Xervice\RabbitMQ\RabbitMQDependencyProvider as XerviceRabbitMQDependencyProvider;
use XerviceTest\LogRabbitMq\Listener\LogListener;
class RabbitMQDependencyProvider extends XerviceRabbitMQDependencyProvider
{
/**
* @return array
*/
protected function getListener(): array
{
return [
new LogListener()
];
}
}