项目作者: t3n

项目描述 :
Sidecar package for t3n.JobQueue.RabbitMQ
高级语言: PHP
项目地址: git://github.com/t3n/JobQueue.Log.git
创建时间: 2019-02-01T11:44:26Z
项目社区:https://github.com/t3n/JobQueue.Log

开源协议:

下载


CircleCI Latest Stable Version Total Downloads

t3n.JobQueue.Log

A sidecar package for t3n.JobQueue.RabbitMQ. This package will log infos
about submitted, failed and finished jobs to a RabbitMQ backend. This package could also be used to simply log some
custom messages.

Setup

To use RabbitMQ as a backend for a JobQueue you need a running RabbitMQ Service. You can use our docker image which also
includes the management console t3n/rabbitmq

Install the package using composer:

  1. composer require t3n/jobqueue-log

Configuration

For a basic setup of RabbitMQ Queues check t3n.JobQueue.RabbitMQ. This
section will only cover the additional configuration.

There are some preconfigured queues:

  1. Flowpack:
  2. JobQueue:
  3. Common:
  4. queues:
  5. # All queues should be adjusted to your needs / configurations to fit your exchange config
  6. # We just provide different queues to send messages with different routing keys to an exchange
  7. # these queues only acts as a producer and dont't need to be declared
  8. log-info:
  9. className: 't3n\JobQueue\RabbitMQ\Queue\RabbitQueue'
  10. options:
  11. routingKey: 'log.info' # Adjust to your needs
  12. queueOptions:
  13. declare: false
  14. log-success:
  15. className: 't3n\JobQueue\RabbitMQ\Queue\RabbitQueue'
  16. options:
  17. routingKey: 'log.success' # Adjust to your needs
  18. queueOptions:
  19. declare: false
  20. log-error:
  21. className: 't3n\JobQueue\RabbitMQ\Queue\RabbitQueue'
  22. options:
  23. routingKey: 'log.error' # Adjust to your needs
  24. queueOptions:
  25. declare: false
  26. log-message:
  27. className: 't3n\JobQueue\RabbitMQ\Queue\RabbitQueue'
  28. options:
  29. routingKey: 'log.message' # Adjust to your needs
  30. queueOptions:
  31. declare: false

Adjust those queues to fit your needs. You probably want to adjust the routing key as well
as the preset / exchange configuration. Those queue names are used internally, so make sure
you got those covered! We won’t declare them as they only act as a producer. There is no need
to declare or persist them for now.

Now add a consumer queue like this:

  1. Flowpack:
  2. JobQueue:
  3. Common:
  4. queues:
  5. log-listener:
  6. className: 't3n\JobQueue\Log\Queue\TransientRabbitQueue'
  7. options:
  8. routingKey: 'log.*'
  9. queueOptions:
  10. declare: true
  11. exchangeName: 'your-exchange'

This queue uses a TransientRabbitQueue. This is important as we override the default queue options
to make sure it has a unique name so you several consumer can connect and all messages
are forwarded to each consumer. The queue will also only exist as long as a consumer is
connected (realised with the exclusive flag).
This queue now would receive all logs with all severities. If you only need warnings adjust
the routing key to your needs or configure another consumer queue.

We wont log anything by default but is able to log logs for submitted, failed and finished jobs.
You can enable logging in your Settings.yaml:

  1. t3n:
  2. JobQueue:
  3. Log:
  4. logFailedJobs: false
  5. logSubmittedJobs: false
  6. logFinishedJobs: false

Usage

After you configured your producer and consumer queues there is a flow command to output
all logs:

  1. ./flow job:work log:live --severity <string> --verbose <bool>

The severity flag controls whether to log only failed Jobs (warning), submitted jobs (info)
or finished jobs (success). By default all logs (*) are outputted.
Setting verbose to true will also display some more meta information.

Send generic messages

This package is made to have a live overview of your jobqueues. But you can also use it
to send some generic logs. Therefore we added the severity message.

Sending a message to all consumers:

  1. /**
  2. * @Flow\Inject
  3. *
  4. * @var JobManager
  5. */
  6. protected $jobManager;
  7. [...]
  8. $message = new LogJob(string $subject, string $label, string $messageBody, array $additionalData, string $severity);
  9. $this->jobManager->queue('log-message', $message);

The queue name, routing keys etc. can be customized to fit your needs!