Advertisement
Guest User

Untitled

a guest
Mar 6th, 2021
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.14 KB | None | 0 0
  1. #config/queue.php
  2.        'rabbitmq' => [
  3.             'driver' => 'rabbitmq',
  4.             'connection' => AMQPStreamConnection::class,
  5.             'options' => [
  6.                 'queue' => [
  7.                     'job' => RabbitMQJob::class,
  8.                     'exchange' => 'logs',
  9.                     'exchange_type' => 'fanout',
  10.                     'exchange_routing_key' => '',
  11.                 ],
  12.             ],
  13.             'worker' => env('RABBITMQ_WORKER', 'default'),
  14.         ]
  15.  
  16.  
  17. #RabbitMQJob.php
  18. namespace App\Queue\Jobs;
  19.  
  20. class RabbitMQJob extends \VladimirYuldashev\LaravelQueueRabbitMQ\Queue\Jobs\RabbitMQJob
  21. {
  22.     public function fire(): void
  23.     {
  24.         \print_r($this);
  25.     }
  26. }
  27.  
  28.  
  29. #emit_log.php
  30. require_once __DIR__.'/vendor/autoload.php';
  31.  
  32. use PhpAmqpLib\Connection\AMQPStreamConnection;
  33. use PhpAmqpLib\Message\AMQPMessage;
  34.  
  35. $connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');
  36. $channel = $connection->channel();
  37. $channel->exchange_declare('logs', 'fanout', false, true, false);
  38. $channel->basic_publish(new AMQPMessage("info: Hello World!"), 'logs');
  39. $channel->close();
  40. $connection->close();
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement